Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:12:44+00:00 2026-06-16T09:12:44+00:00

I have a problem with my code: <?php echo $s_country; $sql2=SELECT prod_id FROM tbl_order_item

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:12:45+00:00Added an answer on June 16, 2026 at 9:12 am

    First Solution:

    Change

    $res=mysql_query($sql3) or die(mysql_error()); // you have overwritten result set of first query
    $shipping_cost1=mysql_fetch_object($res);  
    

    To

    $newres=mysql_query($sql3) or die(mysql_error());
    $shipping_cost1=mysql_fetch_object($newres);
    

    Second Solution (much better):

    $sql2="SELECT GROUP_CONCAT(prod_id SEPARATOR ',') as pid FROM tbl_order_item WHERE order_id='$order_id'";
    $res=mysql_query($sql2) or die(mysql_error());
    
    if(mysql_num_rows($res) > 0){
      $rs=mysql_fetch_array($res);
      $sql3 = "SELECT shipping_us FROM tbl_product WHERE prod_id IN (".$rs['pid'].")";
      $res=mysql_query($sql3) or die(mysql_error());
      while ($row = mysql_fetch_array($res)){
         echo $row['shipping_us']
      }
    }
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the problem...I have just this line of code: <p><div class=author><?php echo $relevantEntry['author'].
I have a problem making a select tag in php code dynamic. I'm creating
Here is a simple code I have problem with: <label id=label1> <?php echo Text
I have a problem in php code inserting values into database (I use PHPMyAdmin).
i am new in php i have a problem in my php code.please help
I am new to PHP and I have a problem in my code. I
I am using gettext in my PHP code, but I have a big problem.
I'm having a strange problem. I have a HTML page with PHP code which
I have a bizzare problem with php date function. code: $numDays = 8; $date
I Have A problem In displaying JS Code In PHP My Code Is <?php

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.