sutphp Posted November 23, 2006 Share Posted November 23, 2006 I have a sql database with around 1700 records in, I've created a field called player_views.Could someone give me a clue to the code I would require to add to the script so that each view would increment the player_view count.I have a unique id of playerID for each record, I've tried a simple table update but I can't get it working.RegardsAndyMSN: [email protected] Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/ Share on other sites More sharing options...
CheesierAngel Posted November 23, 2006 Share Posted November 23, 2006 What's the code you are using? Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/#findComment-129138 Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 [code]<?php$array = mysql_fetch_array(mysql_query("SELECT `player_view` FROM `users` WHERE `users`.`playerid` ='{$playerid}'"));$count = $array['player_view'] + 1;$update=mysql_query("UPDATE `users` SET `player_view` = '{$count}' WHERE `users`.`playerid` ='{$playerid}'");?>[/code]play with that.[ I am sure all the syntax is correct.] Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/#findComment-129147 Share on other sites More sharing options...
sutphp Posted November 23, 2006 Author Share Posted November 23, 2006 I get the following error ??[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ginger/public_html/gtfcstats/player9.php on line 1671[/code]I'm sorry but I'm useless when it comes to php coding Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/#findComment-129167 Share on other sites More sharing options...
ataria Posted November 23, 2006 Share Posted November 23, 2006 alright.change..$array = mysql_fetch_array(mysql_query("SELECT `player_view` FROM `users` WHERE `users`.`playerid` ='{$playerid}'"));to..$query = mysql_query("SELECT `player_view` FROM `users` WHERE `users`.`playerid` ='{$playerid}'");$array = mysql_fetch_array($query); Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/#findComment-129172 Share on other sites More sharing options...
CheesierAngel Posted November 23, 2006 Share Posted November 23, 2006 Try not to use to many nested functions at once.Rather use:[code]<?php$qResults = mysql_query("SELECT `player_view` FROM `users` WHERE `users`.`playerid` ='{$playerid}'");$array = mysql_fetch_array($qResults);$count = $array['player_view'] + 1;$update=mysql_query("UPDATE `users` SET `player_view` = '{$count}' WHERE `users`.`playerid` ='{$playerid}'");?>[/code] Link to comment https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/#findComment-129173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.