Jump to content

Adding together two values from my sql queries


dthomas31uk

Recommended Posts

Hi. Am having trouble adding together two values that are stored in two sql queries.

The values are stored in variables but cannot get it to calulate and display on my webpage.

 

   1. $result = mysql_query("SELECT full_price, half_price FROM eu_place WHERE city = '" . mysql_real_escape_string($subcat) . "'") or die(mysql_error());
   2. $row = mysql_fetch_array($result);
   3. if ($load == 'full_load') {
   4.   echo (" "). $row['full_price'];
   5. } else {
   6.   echo (" "). $row['half_price'];
   7. }
   8. $resultPickup = mysql_query("SELECT price FROM uk_place WHERE city = '" . mysql_real_escape_string($pickup) . "'") or die(mysql_error());
   9. $rowPickup = mysql_fetch_array($resultPickup);

 

And the code I have tried to use to calculate the values is

 

echo $rowPickup['price'] + $row['full_price'];

 

but am getting a blank screen.  Any ideas guys

$result = mysql_query("SELECT full_price, half_price FROM eu_place WHERE city = '" . mysql_real_escape_string($subcat) . "'") or die(mysql_error());
$row = mysql_fetch_row($result);
if ($load == 'full_load') {
echo (" "). number_format($row[0], 2);
} else {
echo (" "). number_format($row[1], 2);
}
$resultPickup = mysql_query("SELECT price FROM uk_place WHERE city = '" . mysql_real_escape_string($pickup) . "'") or die(mysql_error());
$rowPickup = mysql_fetch_row($resultPickup);

 

 

echo "£" . round( ($rowPickup[0] + $row[0]), 2);

 

???

Are you sure you are getting results from your query? Maybe the query returned 0 rows and there's no data to add... Check it out- use print_r($row) and print_r($rowPickup) after your mysql_fetch_array()'s. See if there's data in there and if there is what does it hold.

 

Orio.

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.