squiblo Posted August 20, 2009 Share Posted August 20, 2009 this code enters the hit count into the whole field in my database but i just want it to be entered into a specific row of a user how can i do this? <?php session_start(); ?> <?php // Connects to your Database mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); //Adds one to the counter mysql_query("UPDATE members SET counter = counter + 1"); //Retreives the current count $count = mysql_fetch_row(mysql_query("SELECT counter FROM members")); //Displays the count on your site print "Total hits = $count[0]"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/171071-solved-hit-counter/ Share on other sites More sharing options...
Prismatic Posted August 20, 2009 Share Posted August 20, 2009 I'm assuming you've set up your users table with an ID column, if so mysql_query("UPDATE members SET counter = counter + 1 WHERE user_id = '12345'"); Where user_id is the column name containing the ID, and 12345 is the ID. If you don't have an ID column, mysql_query("UPDATE members SET counter = counter + 1 WHERE username = 'bob'"); Where username is the column name containing the username, and bob is the name. See MySQL: 12.2.11. UPDATE Syntax for more information. Quote Link to comment https://forums.phpfreaks.com/topic/171071-solved-hit-counter/#findComment-902212 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.