Jump to content


Photo

PHP SELECT Where clause has multiple requests


  • Please log in to reply
5 replies to this topic

#1 deemar

deemar
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 02:08 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?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 August 2006 - 02:57 PM

Just add another piece to the WHERE clause... what are you unsure about?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 deemar

deemar
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 03:08 PM

Not sure had to actually add the other piece to the Where clause. I think there is an AND in there but i can't get the correct syntax.

I think.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 30 August 2006 - 04:49 PM

Post whatever you have so far.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 deemar

deemar
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 August 2006 - 06:01 PM

<?php
//$result = mysql_query("SELECT image_name from photo_album WHERE file_name=".$_GET['username'],$db); 

//$result = "SELECT * FROM zen_orders_total Where orders_id='15' AND class='ot_shipping'
//UNION
//SELECT * FROM zen_orders_total Where orders_id='1' AND class='ot_total'";
$result = "select orders_id, (select value from zen_orders_total where orders_id=15 and class='ot_total') as total, (select value from zen_orders_total where orders_id=15 and class='ot_shipping') as shipping from zen_orders_total where orders_id";

//$result11 = mysql_query($result) or die (mysql_error());
$row = mysql_fetch_array($result)




?>


<?php

$shipping_total=$result['shipping'];
$transfer_total=$result['total'];


if ($shipping_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 $shipping_total;
echo $transfer_total;

}else{

echo 'Your shipment total has not been updated.';
echo $shipping_total;
echo $transfer_total;
}
?>


#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 31 August 2006 - 03:53 AM

That's a very different query than what you described.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users