Adding together two values from my sql queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dthomas31uk
Forum Newbie
Posts: 19
Joined: Mon Oct 13, 2008 8:14 am

Adding together two values from my sql queries

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Adding together two values from my sql queries

Post by onion2k »

$rowPickup will be an array.
dthomas31uk
Forum Newbie
Posts: 19
Joined: Mon Oct 13, 2008 8:14 am

Re: Adding together two values from my sql queries

Post by dthomas31uk »

Have tried that
echo $rowPickup['price'] + $row['full_price'];

but still get a blank screen
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Adding together two values from my sql queries

Post by onion2k »

Are the two values actually set?
dthomas31uk
Forum Newbie
Posts: 19
Joined: Mon Oct 13, 2008 8:14 am

Re: Adding together two values from my sql queries

Post 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());
?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Adding together two values from my sql queries

Post by onion2k »

I mean do $rowPickup['price'] and $row['full_price'] actually contain anything?
dthomas31uk
Forum Newbie
Posts: 19
Joined: Mon Oct 13, 2008 8:14 am

Re: Adding together two values from my sql queries

Post 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);
Post Reply