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

Link to comment
Share on other sites

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

 

???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.