Jump to content

Recommended Posts

I have a question about how to do a query the best way possible.

 

Right now our company has an order system which allows you to place orders with us.  The main table contains all the information about the order but it also contains tables with information attached to that order as well, for instance, tracking numbers, items ordered.  My question is when I do a query to display the order information and also want to have it display the tracking numbers attached to that order how would I go about doing that in a single query?  I'm trying to figure out the most efficient way to code this because i forsee having to use this in similar instances.

 

Let me give some examples:

 

the order table has an ID column as well as a bunch of information including order number, billing info, ordered by, etc.

 

the tracking number table has an ID column, tracking number, shipping carrier and an ID for the order it's attached to.

 

 

I want to make a query that displays a list out of all the orders let's say and in that table I want to display all the tracking numbers that match that order as well.

 

so basically

 

ordernum billto trackingnum

D100      Jon  1938319183

                    1193930102

 

D101      Tim  1030040313

 

D102      Bill    1300203000

                    1393949299

                    3939293939

 

 

Link to comment
https://forums.phpfreaks.com/topic/85029-solved-question-of-best-procedure/
Share on other sites

When you say that what exactly do you mean?  After I get the results from the query I take the results and use a loop to display the columns I want in an HTML table.

 

so an example of a possible output would be formatted like this from the join

 

Order Number    Bill To    Tracking Number

 

D101              Tom's      100302030

D101              Tom's      102003010

D101              Tom's      103994828

D102              Joe's      100300302

D103              Tim's      100303020

D103              Tim's      100030202

 

That's just arbitrary but that's how it displays.  I'd like to take the data and display it in a fashion more similar to this

 

Order Number    Bill To    Tracking Number

D101              Tom's      100302030

                                  102003010

                                  103994828

 

D102              Joe's      100300302

 

D103              Tim's      100303020

                                  100030202

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.