Ruko Posted May 1, 2010 Share Posted May 1, 2010 I find that my play counter isn't working like its supposed to. It doesn't update the play counts in each row. Can someone give me a solution to fix? The snippet of the counter: //////////////////////////////// //////////////////////////////// ////////// Counter ///////////// //////////////////////////////// //////////////////////////////// $csql="SELECT * FROM games WHERE gid='$gid'"; $cresult=mysql_query($csql); $crows=mysql_fetch_array($cresult); $counter=$ccolumn['counter']; // if have no counter value set counter = 1 if(empty($counter)){ $counter=1; $csql1="UPDATE 'games' SET counter = '$counter' WHERE gid = '$gid'"; $cresult1=mysql_query($csql1); } // count more value $addcounter=$counter+1; $ccsql2="UPDATE 'games' SET counter = '$addcounter' WHERE gid = '$gid'"; $cresult2=mysql_query($csql2); Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/ Share on other sites More sharing options...
mikesta707 Posted May 1, 2010 Share Posted May 1, 2010 i dont see where you define $gid. Does that page cause any errors? Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051399 Share on other sites More sharing options...
Ruko Posted May 1, 2010 Author Share Posted May 1, 2010 No, it doesn't cause errors. Heres where I define those $gid tags <?php require_once("mysql.php"); mysql_select_db("ruko_fp", $con); $thispage = $_SERVER["REQUEST_URI"]; $gid = strstr("$thispage","="); $gid = substr($gid, 1); $result = mysql_query("SELECT * FROM games WHERE gid='$gid'"); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "Sorry! You reached a page or a game that doesn't exist. Please check your URL and try again. If the problem continues, then contact the webmaster or use the report us system."; } else { while($row = mysql_fetch_array($result)) { $flashlink = $row['gameswf']; $gid = $row['gid']; $gametitle = $row['gametitle']; $gamedescription = $row['gamedescription']; $gamerating = $row['gamerating']; $gamereview = $row['gamereview']; } } Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051401 Share on other sites More sharing options...
mikesta707 Posted May 1, 2010 Share Posted May 1, 2010 well you don't seem to include the page where you are defining $gid in the script you posted above. unless you left that part out. to debug, try echoing the values of some of your variables, and see if they have what you think they have. for example, use print_r on your $crow variable print_r($crow); to verify that you are actually selecting something Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051402 Share on other sites More sharing options...
Ruko Posted May 1, 2010 Author Share Posted May 1, 2010 The main problem is that the play count is not adding in the sql row. Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051404 Share on other sites More sharing options...
mikesta707 Posted May 1, 2010 Share Posted May 1, 2010 yes I understand, but if your script doesn't know $gid, then it won't work. try echoing $gid at the top of the page and make sure its defined. I don't see anything else wrong with the script (aside from some possible security errors) Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051405 Share on other sites More sharing options...
darkdc Posted May 1, 2010 Share Posted May 1, 2010 $counter=$ccolumn['counter']; Is that supposed to be $crows['counter'] instead? Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051411 Share on other sites More sharing options...
Ruko Posted May 1, 2010 Author Share Posted May 1, 2010 Oh, I almost forgot to mention, its on a structure, heres what it looks like: [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051415 Share on other sites More sharing options...
Ruko Posted May 1, 2010 Author Share Posted May 1, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1051589 Share on other sites More sharing options...
Ruko Posted May 2, 2010 Author Share Posted May 2, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1052060 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Okay, a few things: $csql1="UPDATE 'games' SET counter = '$counter' WHERE gid = '$gid'"; Don't put single quote around games. It's a table name, not a string. $counter=$ccolumn['counter']; $ccolumn is not defined. Also, your code is redundant. Just run: mysql_query("UPDATE games SET counter = counter + 1 WHERE gid = '$gid';") or trigger_error(mysql_error()); No need for all the checks. That will add 1 to counter. Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1052064 Share on other sites More sharing options...
Ruko Posted May 2, 2010 Author Share Posted May 2, 2010 It works! Thanks man. Quote Link to comment https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/#findComment-1052133 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.