Jump to content

Problem with mysql getting prices from table


Nothadoth

Recommended Posts

Hey guys,

 

I have two tables set up - tbl_order_item and tbl_product. I have session id's set and product id's to link the two tables. Each product has pd_price1, pd_price2 and pd_price3. The tbl_order_item has a pd_type field (1, 2, or 3) which is working and is filled with the relevant number when the user has completed the checkout.

 

I am trying to get the final price and send it to Paypal. So it uses the session id to find the right rows in tbl_order_item and give my the pd_type and then use that variable to find the correct price from tbl_product.

 

Here is my code:

 

function getOrderAmount($orderId)
{
$orderAmount = 0;

$sql = "SELECT pd_type
        FROM tbl_order_item 
        WHERE od_id = $orderId
		";
$result = mysql_query($sql);
while($row = dbFetchRow($result)) {
	$type = $row['pd_type'];

$sql = "SELECT SUM(pd_price$type * od_qty)
        FROM tbl_order_item oi, tbl_product p 
	    WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId

		UNION

		SELECT od_shipping_cost
		FROM tbl_order
		WHERE od_id = $orderId";

		$result = dbQuery($sql);
if (dbNumRows($result) == 2) {
	$row = dbFetchRow($result);
	$totalPurchase = $row[0];

	$row = dbFetchRow($result);
	$shippingCost = $row[0];

	$orderAmount = $totalPurchase + $shippingCost;
}	

return $orderAmount;	
}


}

 

This returns this error:

Notice: Undefined index: pd_type in /home/wwwdist/public_html/elite/library/checkout-functions.php on line 88

Unknown column 'pd_price' in 'field list'

 

I dont understand why it isnt getting pd_type from the database table and putting it at the end of pd_price. Probably something stupid here. But ive been messing with code all day and my mind is just boggled now.

 

Thanks

Link to comment
Share on other sites

As a test, I echo'd the orderId variable and it came up as 1106. I checked the database and that row did exist with that id. the pd_type field was assigned to '2'. Yet in this code it is trying to retrieve this field and fails.........

 

Im completely lost.

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.