Jump to content

Querying table results


ccompass

Recommended Posts

I have three tables: events, orderdetails & orders.

 

First I query orderdetails to find all the records that match the EventID:

 

$query1 = SELECT * FROM orderdetails WHERE EventID = $_SESSION['EventID'];

 

This returns 4 records.  These 4 records have a field called DetailOrderID which is the foreign key for orders.OrderID.  Next I need to query the results of the first query to find all the records in the orders table that match up.  For example:

 

SELECT * from orders where $query1.DetailOrderID = orders.OrderID.

 

How would I go about doing this?  I'm head down the temporary table solution but wanted to through this one out for discussion before I invest too much time.

Link to comment
Share on other sites

Here are the two tables:

 

orderdetails

-------------------------

DetailID (PK)

DetailOrderID

DetailProductID

EventID

DetailName

DetailPrice

DetailQuantity

 

orders

------------------------

OrderID (PK)

OrderAmount

OrderShipName

OrderShipAddress

OrderCity

OrderState

OrderZip

OrderPhone

OrderEmail

OrderDate

 

This code seems to work, but I don't know how to query the $result array.

 

$result = mysql_query("SELECT * FROM orderdetails WHERE EventID =" . $_GET['EventID']) or die(mysql_error());  

while($row = mysql_fetch_array($result)){
echo "DetailID: " . $row['DetailID'] . " | DetailOrderID: " . $row['DetailOrderID'] . "<br>";
}

 

 

 

Link to comment
Share on other sites

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.