redarrow Posted July 23, 2006 Share Posted July 23, 2006 advance thank you.high there i am trying to get the $hits to increment by one,when the page loads the first 1 goes in but then onwards nothink please help cheers.my code example cheers.[code]<?if($_GET['cmd']=="update"){$query_update="update member_topics set hits=$hits+1 where date_added='".$_GET['date_added']."' and time_added='".$_GET['time_added']."' and user_id='".$_GET['user_id']."'";$result_query=mysql_query($query_update);echo $query_update;}?>[/code]database query result please help[code]update member_topics set hits=+1 where date_added='23-07-06' and time_added='10:06:14' and user_id='00002'[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/ Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 try hits=hits+1 Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62516 Share on other sites More sharing options...
Joe Haley Posted July 23, 2006 Share Posted July 23, 2006 or place $hits++; on the line before the query. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62518 Share on other sites More sharing options...
redarrow Posted July 23, 2006 Author Share Posted July 23, 2006 ok hits=hits+1 worked cheers but as always lol...........if the user resfresh the page that hit will keep going up any idears cheers php only theo. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62523 Share on other sites More sharing options...
AndyB Posted July 23, 2006 Share Posted July 23, 2006 Bit of clarification, please.If I 'refresh' page X, you don't want the hits to increase. If I visit another page on the site and then navigate back to page X, should hits increment? If I leave your site and come back later to page X, should hits increment? If I was away for an hour, or away for a week, would it matter in your answer to my last question. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62530 Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 [quote author=redarrow link=topic=101591.msg402187#msg402187 date=1153690860]ok hits=hits+1 worked cheers but as always lol...........if the user resfresh the page that hit will keep going up any idears cheers php only theo.[/quote]Duh... ??? Ofcourse it does. To avoid that you'll have to link the view of a page to the client.Possible solutions:1) link the hit to the sessionid or even stored username/id2) link the hit to a client with a cookie3) link the hit to a client by ipTake your pick. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62532 Share on other sites More sharing options...
redarrow Posted July 23, 2006 Author Share Posted July 23, 2006 andy was going to use sleep() or set_time_limit()but the problam is that i wanted to add a function that a user can not refresh the same page.so that the hits dont increment on a page that there viewing but the page is also the page that they will view other topics.example a user goto a topic they like the user press the refresh button the user gets a echoed message from that viwing page and database entry.i thort that i get the users ip while on the page of viewing then let them sleep or echo a message what do youthink works better. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62534 Share on other sites More sharing options...
redarrow Posted July 23, 2006 Author Share Posted July 23, 2006 i want to get the user ipuser=$_SERVER['REMOTE_ADDR'];if the user refreshsend them to the home page.header("location: index.php");what i need to know how wili now the user has press refresh.example only<?$user_ip=$_SERVER['REMOTE_ADDR'];$kept_session=$_SESSION['kept']=$user_ipif($user_ip == $kept_session ) {header("location: index.php")}?> Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62537 Share on other sites More sharing options...
redarrow Posted July 23, 2006 Author Share Posted July 23, 2006 solvedwhen the user press the button the link will send them to a update page then rediret to the topic there viewing cheers. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62540 Share on other sites More sharing options...
448191 Posted July 23, 2006 Share Posted July 23, 2006 I, like Andy, am still a bit confused at what exactly your goal is. But I'm assuming you want to link the page view to the clients' ip... There's a reason it's the third option and not the first or second, but nevermind.Let's focus on what YOU want to do (if I understand correctly):Store the pages a specific ip has already visited, so count won't increase on second visit.How? Store the data linking an url to several ip's.Example:INSERT INTO hits (url,ip) VALUES (**,**)Include an UNIQUE index on the ip column. Inserting the same ip twice will fail. Add a TIMESTAMP column for garbage collection purposes.To get the full hit count:SELECT count(ip) FROM hits WHERE url = *EDIT:Pfff... This is getting obnoxious. Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62545 Share on other sites More sharing options...
redarrow Posted July 24, 2006 Author Share Posted July 24, 2006 this was solved but cheers anyway lol........................... Quote Link to comment https://forums.phpfreaks.com/topic/15423-increment-by-1-please-help-cheers/#findComment-62646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.