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
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Wed Oct 15, 2008 3:28 am
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
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Oct 15, 2008 3:32 am
$rowPickup will be an array.
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Wed Oct 15, 2008 3:38 am
Have tried that
echo $rowPickup['price'] + $row['full_price'];
but still get a blank screen
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Oct 15, 2008 3:41 am
Are the two values actually set?
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Wed Oct 15, 2008 3:43 am
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 (" "). $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);
echo $rowPickup + $row['full_price'];
mysql_error());
?>
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Oct 15, 2008 4:02 am
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
Post
by dthomas31uk » Wed Oct 15, 2008 4:12 am
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);