Jump to content

[SOLVED] How do I get the result of this Mysql Query?


alexville

Recommended Posts

One more thing, how would I check if the result was empty, and instead say it was 0 views?

 

Okay,

 

It works when the person has more than 0 views, but when they have no views it just shows up as this: Your games have received views all together!

 

The number zero doesnt show up where it should be between received and views.

 

$a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'");

$views = 0;

if (mysql_num_rows($a) > 0) {

    $views = mysql_fetch_array($a);

    $views = $views[0];

}

 

 

echo "Your games have received <strong>$views</strong> views all together!";

 


$a = mysql_query("SELECT SUM(`views`) FROM games WHERE uploader = '$session->username'"); 
$views = 0;
if (mysql_num_rows($a) > 0) {
    $views = mysql_fetch_array($a);
    $views = $views[0];
    if (empty($views) || $views == "") 
        $views = 0;
}

echo $views;

 

Try that. It is simple if logic....

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.