Jump to content

Help with a record hit counter


sutphp

Recommended Posts


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.

Regards

Andy
MSN: [email protected]
Link to comment
https://forums.phpfreaks.com/topic/28240-help-with-a-record-hit-counter/
Share on other sites

[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.]
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);
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.