I have a problem with my code:
<?php
echo $s_country;
$sql2="SELECT prod_id FROM tbl_order_item WHERE order_id='$order_id'";
$res=mysql_query($sql2) or die(mysql_error());
$i=0;
$j="";
while($rs=mysql_fetch_array($res)){
$j = $rs['prod_id'];
if(trim($s_country)=='US' || trim($s_country=='United States' )){
$sql3 = "SELECT shipping_us FROM tbl_product WHERE prod_id=".$j;
$res=mysql_query($sql3) or die(mysql_error());
$shipping_cost1=mysql_fetch_object($res);
}
$i++;
}
?>
What I actually want to do is to fetch the products id from the table tbl_order_item and with that products id select the shipping cost for those ids from the table tbl_product.
For example, if there is two product ids, it should select shipping cost for both the ids.
But here it only works for one product id like this:
SELECT shipping_us FROM tbl_product WHERE prod_id=526
But what I’m trying to do is :
SELECT shipping_us FROM tbl_product WHERE prod_id=526
SELECT shipping_us FROM tbl_product WHERE prod_id=527
First Solution:
Change
To
Second Solution (much better):
Recommendations:
1.Learn to prevent from MySQL Injections: Good Link
2.Mysql extension is not recommended for writing new code. Instead, either the mysqli or PDO_MySQL extension should be used. More reading: PHP Manual