Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.