Ok this might be hard to explain but ill to my best, and hopefully someone can help me out here.
I have a table with the following columns:
purchaseID, orderID, Description, etc..
Now purchaseID is like a bundle of a purchase. And orderID is for items.
So say you make a purchase of 3 items. here is what the table would look like.
YOu would have 3 rows.
purchaseID | orderID | description | UserID
1 1 Book 1
1 2 CD-ROM 1
1 3 TV 1
note userID is linked to a user table with all the users information.
Now what i want to do is this:
List each user with the products that they have bought:
Something like this:
Derek C
#1. Book
#2. CD-ROM
#3. TV
Now that is 1 bundle or a purchase. if i were to say buy 2 more items another day thats a new bundle so it would look liek this:
purchaseID | orderID | description | UserID
2 1 VCR 1
2 2 Bed 1
Now what i have is it listing fine, but if you have 2-3-4... differnet purchaseID's with the same userID then it will print all of them the number of different purchaseID's you have to your userID.
Here are my queries:
// First Row with purchase ID
$query1 = "SELECT purchase., user. FROM purchase, user
WHERE purchase.userID = user.userID order by purchaseID";
$result1 = mysql_db_query ($database_name, $query1, $conn);
while ($r1 = mysql_fetch_array($result1))
{
$purchaseID = $r1["purchaseID"];
$firstname = $r1["firstName"];
$lastname = $r1["lastName"];
$userID = $r1["userID"];
echo"$firstname $lastname";
/// Second row with orderID
$query2 = "SELECT * FROM purchase WHERE purchaseID = '$purchaseID'";
$result2 = mysql_db_query ($database_name, $query2, $conn);
while ($r2 = mysql_fetch_array($result2))
{
$orderID = $r2["orderID"];
$comments = $r2["comments"];
echo"$orderID - $comments";
}
// End Purchase ID