Page 1 of 1

Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 3:28 am
by dthomas31uk
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

Code: Select all

$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_array($result);
if ($load == 'full_load') {
  echo (" "). $row['full_price'];
} else {
  echo (" "). $row['half_price'];
}
$resultPickup = mysql_query("SELECT price FROM uk_place WHERE city = '" . mysql_real_escape_string($pickup) . "'") or die(mysql_error());
$rowPickup = mysql_fetch_array($resultPickup);
And the code I have tried to use to calculate the values is

Code: Select all

echo $rowPickup + $row['full_price'] ;
but just get a blank screen. Any ideas guys

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 3:32 am
by onion2k
$rowPickup will be an array.

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 3:38 am
by dthomas31uk
Have tried that
echo $rowPickup['price'] + $row['full_price'];

but still get a blank screen

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 3:41 am
by onion2k
Are the two values actually set?

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 3:43 am
by dthomas31uk
Don't know what you mean jedi.

This is the code that handles all the values for the page.

Code: Select all

<?php
$pickup=$_POST['pickup'];
$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$load=$_POST['load'];
echo "Value of \$pickup = $pickup" ."<BR>";
echo "Value of \$cat = $cat <br>Value of \$subcat = $subcat"."<BR>";
echo "Value of \$load = $load";
 
 
$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_array($result);
 
if ($load == 'full_load') {
  echo ("&nbsp;"). $row['full_price'];
} else {
  echo ("&nbsp;"). $row['half_price'];
}
 
 
$resultPickup = mysql_query("SELECT price FROM uk_place WHERE city = '" . mysql_real_escape_string($pickup) . "'") or die(mysql_error());
$rowPickup = mysql_fetch_array($resultPickup);
 
echo $rowPickup + $row['full_price']; 
 
 
mysql_error());
?>

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 4:02 am
by onion2k
I mean do $rowPickup['price'] and $row['full_price'] actually contain anything?

Re: Adding together two values from my sql queries

Posted: Wed Oct 15, 2008 4:12 am
by dthomas31uk
yes they do. I have echoed the results before I have tried adding the two arrays. The value of pickup is a string and from that value I did the following

Code: Select all

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