Jump to content

[SOLVED] How can I add the result of the query?


thecard

Recommended Posts

I have a simple SELECT query:

 

$query3 = mysql_query("SELECT hits FROM tb_sites WHERE user='$user'")  or die(mysql_error());
$row3 = mysql_fetch_array($query3);

 

Then I echo the output. "Hits" is a number btw.

 

But if there is more than one output (more than 1 occurence of a record with user='$user') I want to add the outputs together and store that number in a variable.

How could I do this?

$query3 = mysql_query("SELECT hits FROM tb_sites WHERE user='$user'")  or die(mysql_error());
$row3 = mysql_fetch_array($query3);

 

instead of use this

$query3 = mysql_query("SELECT COUNT(hits) as TotalHits FROM tb_sites WHERE user='$user'")  or die(mysql_error());
$row3 = mysql_fetch_array($query3);

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.