Jump to content


Photo

Combine SQL with PHP


  • Please log in to reply
1 reply to this topic

#1 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 22 August 2006 - 09:19 PM

Hi I originally posted this is the database forum but I think its more a PHP problem now. I recently had to seperate my two queries as the server that I need to use does not support the UNION function. I have been told to combine them but not sure how to. Can anyone please assist. Thank You

$sql = "SELECT SUM(pd_price * od_qty) 
            FROM tbl_order_item oi, tbl_product p 
            WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId"; 
             
$result1 = dbQuery($sql); 
                     
$sql2 = "SELECT od_shipping_cost 
            FROM tbl_order 
            WHERE od_id = $orderId"; 
$result2 = dbQuery($sql2); 

if (dbNumRows($result1) == 2) {
		$row = dbFetchRow($result1);
		$totalPurchase = $row[0];
		
		$row = dbFetchRow($result2);
		$shippingCost = $row[0];
		
		$orderAmount = $totalPurchase + $shippingCost;
	}	
	
	return $orderAmount;	
}
Any help will be great. THX :)

#2 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 23 August 2006 - 10:25 AM

solved prob! it was as simple as adding

if (dbNumRows($result1) == 1 && dbNumRows($result2) == 1) { 


because previously if (dbNumRows($result1) == 2) {
this means that id expect there to be 2 rows as a result of the UNION query. by separating the queries each should have at least 1 record.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users