Jump to content

My play counter not working


Ruko

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/200345-my-play-counter-not-working/
Share on other sites

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'];

        }

      }

 

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

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.

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.