Jump to content

Combine SQL with PHP


crazylegseddie

Recommended Posts

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

[code]
$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;
}
[/code]
Any help will be great. THX :)
Link to comment
Share on other sites

solved prob! it was as simple as adding

[code]
if (dbNumRows($result1) == 1 && dbNumRows($result2) == 1) {

[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.