ohdang888 Posted December 31, 2007 Share Posted December 31, 2007 hey. i want to create a counter for a page using mysql. does mysql let you use php to perform functions on the information retrieved? and if so, it would the outline be... -connect -get old counter value -add 1(using php) -save new value -display new value- ???????????????? Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/ Share on other sites More sharing options...
MadTechie Posted December 31, 2007 Share Posted December 31, 2007 So whats the problem your having? what code do you have so far ? Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426760 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 well i tried to do this: for example... it would be in game.php?title=2deep and would grab all the info from the row of 2deep, including the counter <?php function sql_quote($data) { if (get_magic_quotes_gpc()) { $data = stripslashes($data); } return addslashes($data); } $game = sql_quote($_GET['title']); mysql_connect("localhost", "-----", "-----") or die(mysql_error()); mysql_select_db("games") or die(mysql_error()); $result = mysql_query("SELECT `author`,`title`,`author_url`,`type`,`flash`,`game_picture_url`,`game_file_name`,`instructions`,`counter` FROM `game` WHERE `title`='{$game}'") or die(mysql_error()); $row = mysql_fetch_array($result); $oldcounter = stripslashes($row['counter']); $oldcounter++ = $newcounter ?> buts its saying the stuff below the array is not valid. Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\counter.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426829 Share on other sites More sharing options...
revraz Posted December 31, 2007 Share Posted December 31, 2007 $oldcounter += $newcounter; Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426835 Share on other sites More sharing options...
corillo181 Posted December 31, 2007 Share Posted December 31, 2007 the way i have my counter is mysql_query("UPDATE table SET count=(count + 1)"); i had count with a value of 0 so from there on every time the page is view only has to add one. Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426848 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 well this table has tons of games in it. so will it automatically update the counter in the same row of the game?????? (look at the code i posted 3 posts ago) Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426852 Share on other sites More sharing options...
ohdang888 Posted December 31, 2007 Author Share Posted December 31, 2007 nvm. i tested it and it updates EVERY counter of every game in the table. but i put WHERE `title`='{$game}'"); THANKS GUYS! Quote Link to comment https://forums.phpfreaks.com/topic/83853-solved-mysql-site-counter/#findComment-426856 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.