Jump to content

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


Recommended Posts


$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 $views;

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

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.