Jump to content

Recommended Posts

Hi Can anyone help please .

 

I am trying to write a function. The code is passed a variable which is used in a mysql query. (Code below) In the second to last line I always get 0 as a result when I know the result should be 3. If i use the following code I get the correct result

 

$screen_size = "i100s" ;

$result = mysql_query("SELECT SUM($screen_size) FROM event WHERE jobstatus = 'confirmed' ")  ;

 

while($row = mysql_fetch_array($result)){

$res = $row['SUM($screen_size)'] ;

 

echo "Total ". $row['jobstatus']. " = ". $res ;

echo "<br />";

 

In the second to last line I always get 0 as a result when I know the result should be 3. If i use the following code I get the correct result

 

$screen_size = "i100s" ;

$result = mysql_query("SELECT SUM($screen_size) FROM event WHERE jobstatus = 'confirmed' ")  ;

 

while($row = mysql_fetch_array($result)){

 

$res = $row['SUM(i100s)'] ;

 

echo "Total ". $row['jobstatus']. " = ". $res ;

echo "<br />";

 

Can anyone offer some advice ?

 

Thanks Mick

 

Link to comment
https://forums.phpfreaks.com/topic/157281-solved-aggregate-functions/
Share on other sites

Doesn't matter.  Probably is.  The problem is that you're using single quotes (' ') around your array key ($row['SUM($screen_size)']) so variables don't interpolate.  Use double quotes.

That's not it. You can't run SUM outside of a query. o.O Well, unless it's a function.

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.