...

View Full Version : PHP SELECT Where Clause with multiple requests



deemar
08-30-2006, 04:20 PM
This is the code i am working with:

<?php

//$result = mysql_query("SELECT * FROM zen_orders Where orders_id=".$_GET['order_id']);
$sql = "SELECT * FROM zen_orders_total Where orders_id=".$_GET['order_id'];
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result)

?>


<?php
$ot_shipping_amount=$row['class->ot_shipping'];
$ot_total_amount=$row['class->ot_total'];
//echo $ot_shipping_amount;


if ($ot_shipping_amount>0) {

echo "<a target='_blank' href='https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=some@mail.net&item_name=Online_Order&item_number=&amount=$ot_total_amount&no_shipping=2&no_note=1&currency_code=USD&bn=PP-BuyNowBF&charset=UTF-8'>Please click here to Pay.</a>";

}else{

echo "Your shipment total has not been updated.";
}
?>
Here is a link to view the table i am working with.
http://onpointsys.com/table.jpg

What i am tryint to achieve:
I would like to SELECT a clause with two Where's. Example, one by order_id from the URL which i have already done and also by the class column which has a value of ot_shipping but must also query the data in the value column .

Then i am trying to create an if statement where if the ot_shipping value is greater than zero display the link if not echo the text above.

So at the end i am trying to get the following results.
order_id=1 and ot_shipping=144.2700 so that i can then place ot_shipping in a variable.

Any ideas?

Fu86
08-30-2006, 04:32 PM
Try this:



$sql = "SELECT * FROM zen_orders_total Where orders_id=".$_GET['order_id']." AND class=".$_GET['class'];

deemar
08-30-2006, 04:53 PM
I think that is taking me in the right direction but the class is not in the url. I have to extract that from the database.

What i need, by looking at the image, is the data in the value column sorted by the class (column) entry of ot_shipping based on the order_id from the URL. This would give me the value of 144.2700 so that i can then create a variable.

Hope that makes sense. I work with PHP as needed.

Ideas?

deemar
08-30-2006, 05:52 PM
I got it to work. Wow. Thanks Fu86. With you advice i was able to change the code like this:

<?php
$sql = "SELECT * FROM zen_orders_total Where orders_id=".$_GET['order_id'] . AND class='ot_shipping'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result)

?>


<?php
$transfer_total=$row['value'];

if ($transfer_total>0) {

echo "<a target='_blank' href='https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=carrellcustom@sbcglobal.net&item_name=Online_Order&item_number=&amount=$transfer_total&no_shipping=2&no_note=1&currency_code=USD&bn=PP-BuyNowBF&charset=UTF-8'>Please click here to Pay.</a>";
echo $transfer_total;

}else{

echo "Your shipment total has not been updated.";
echo $transfer_total;
}
?>
After the code was in place i was able to get the correct entry in the database and display it on the screen to make sure it had the correct value.

Thanks a million.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum