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

  • SEARCH
  • Home
  • 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 6926825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:58:06+00:00 2026-05-27T10:58:06+00:00

The question title is not very clear so let me explain. I am trying

  • 0

The question title is not very clear so let me explain.

I am trying to make a table that gets all line items for a specific order so I am using a loop to get the all the line items for the order however my line item table structure is as follows

|Id (pk)| Order_Id (fk) | Line_Id | Item_Id (fk) | Item_Qty | Item_Price | Line_Total|
|1      | 1             | 1       | 1            | 1        | 25         |25         |
|2      | 1             | 2       | 2            | 3        | 6          |18         |

I now want to make a query within this loop get the item_number from the items table so it can display not just the item_id which is a little vague.

my main problems are I can’t seem to figure out how to get the query to know which item_id to use in the WHERE clause of the SQL statement. and also how to make the loop not run for within the loop for each time that the parent loop/query is running i.e. 3 line items so the the sub-query/loop is going to run 3 times instead of once because there are 3 values in the array through which it is looping.

$id = $_GET['id'];

$query = "SELECT * ";
$query.= "FROM quotes ";
$query.= "WHERE id = {$id}";

$confirmed_query = confirm_query($query);
    if (!$confirmed_query) {
        echo "Query Failed".mysql_error();
        }

$query = mysql_query($confirmed_query);

$query_result = mysql_fetch_assoc($query);

echo "<table border=\"1\"><tr>";

foreach ($query_result as $key => $value) {
    echo "<th>".ucwords(str_replace("_", " ", $key))."</th>";
    }

echo "</tr><tr>";

foreach ($query_result as $key => $value) {
    echo "<td>{$value}</td>";
    }

echo "</tr></table><br /><br /><table border=\"1\"<tr>";

$query = "SELECT * ";
$query.= "FROM quote_details ";
$query.= "WHERE quote_id = {$id}";

$confirmed_query = confirm_query($query);
    if (!$confirmed_query) {
        echo "Query Failed".mysql_error();
        }

$query = mysql_query($confirmed_query);
$header_written = false;
echo "</tr><tr>";
while ($query_result = mysql_fetch_assoc($query)) {
    while ($header_written == false) {
        foreach ($query_result as $key => $value) {
            echo "<th>".ucwords(str_replace("_", " ", $key))."</th>";
            $header_written = true;
            }
        }
    echo "</tr><tr>";   

    //problem starts here 

    foreach ($query_result as $key => $value) {

        $item_query = "SELECT item_number ";
        $item_query.= "FROM items ";
        $key_item = $key;
        $item_query.= "WHERE id = {$key_item}";

        $confirmed_query = confirm_query($item_query);
            if (!$confirmed_query) {
                echo "Query Failed".mysql_error();
                }

        $item_query = mysql_query($confirmed_query);
        while ($item_number = mysql_fetch_assoc($item_query)) {
            foreach ($item_number as $item) {
                echo $item;
            }
        }

        echo "<td>{$value}</td>";
        }
    }
echo "</tr></table>";

Please don’t mind the display html being mixed with the sql queries.

any help on how to approach this would be great i am just can’t seem to find an angle to begin to work this.

Thanks.

  • 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-05-27T10:58:07+00:00Added an answer on May 27, 2026 at 10:58 am

    Rather than do it in a loop, use a SQL JOIN

    You will need something like this

    SELECT * 
    FROM quotes AS q 
    JOIN quote_details AS qd ON qd.quote_id = q.id 
    JOIN items AS i ON i.id = qd.item_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title of this question is not very clear but I cannot explain what
First off, I'm not entirely sure that my question title is very descriptive, so
Sorry for a long question and not a very descriptive title, but my problem
My question is not clear at title [i can not write it exactly] e.g
I am not sure how clear my question is by the title, but I
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
Sorry for the not very descriptive question title. I'm not very sure how to
Firstly, sorry about the question title, it may not be very descriptive for my
Probably very simple question (I just want to ensure I'm right). Title is not
Maybe the title of the question is not very self-explanatory but I don't know

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.