dthomas31uk Posted October 15, 2008 Share Posted October 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
Orio Posted October 15, 2008 Share Posted October 15, 2008 Try adding brackets around the mathematical expression: echo ($rowPickup['price'] + $row['full_price']); Orio. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 15, 2008 Share Posted October 15, 2008 echo round( ($rowPickup['price'] + $row['full_price']), 2); Quote Link to comment Share on other sites More sharing options...
dthomas31uk Posted October 15, 2008 Author Share Posted October 15, 2008 tried both urs andy and orio and still no joy. Am tearing my hair out...aaarrggghh Quote Link to comment Share on other sites More sharing options...
Andy-H Posted October 15, 2008 Share Posted October 15, 2008 $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); ??? Quote Link to comment Share on other sites More sharing options...
Orio Posted October 15, 2008 Share Posted October 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.