Printing from two table within a loop

Help please .....

I am printing data using a loop form one table ... this wirks fine .. now I need to print data based on the record I'm printing at the time .. my code pulls data from the second table but it pulls the same data for every record ...  I'm sure I need a loop within the loop but I can't get it to work .. HELLLLLLLLLLLLP !!!

here is my existing code

$query = "SELECT * FROM horses WHERE status = 'accepted' ORDER BY lot_num";
$results = mysql_query($query)
or die(mysql_error());

<table cellpadding="10" cellspacing="0" border="0">
<tr><td><b>Lot</b></td><td><b>Horse</b></td><td><b>Bid</b></td><td><b>Status</b></td><td><b>Closing Time</b></td></tr>
while ($row = mysql_fetch_array($results)) {
echo "<tr>\n";
echo "<td valign=top rowspan=2>" . $row['lot_num'] . "</td>\n";
echo "<td valign=top rowspan=2><a href='details.php?horse_name=" . $row['horse_name'] . "'>" . $row['horse_name'] . "<br>\n";
echo "<img src='foalpics/" .$row['main_pic']. "' width='75px' alt='" . $row['main_pic'] . "'></td>\n";
echo "<td valign=top height=15>$" . $row['bid'] . "</td>\n";
echo "<td valign=top height=15>" . $row['bidding_status'] . "</td>\n";
echo "<td valign=top height=15>". $row['closing_date'] . " " . $row['closing_time'] . "</td>\n";
echo "</tr>\n";

$pedquery = "SELECT * FROM pedigree, horses WHERE pedigree.horseID = '" . $_SESSION['horseID'] . "' AND horses.horseID = '" . $_SESSION['horseID'] . "'";
$pedresults = mysql_query($pedquery)
     or die(mysql_error());
$ped = mysql_fetch_array($pedresults);

echo "<tr><td colspan=3 height=55>" . $ped['S_Name'] . " X "  . $ped['DS_Name'].  " X " . $ped['DDS_Name'] . " </td></tr>\n";

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think I see it now.
In each loop, your going through and performing the $pedquery.  The same query every single time because your taking the information from the $_SESSION every time.  Did you want the 2nd query to base its information off of the first query?  Your gonna need to change that 2nd query if you want it to be different each time.

Joe P

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
koochyAuthor Commented:
I need to pick the pedigree information based on each horse so the horse id from the first query.
koochyAuthor Commented:
Ah ha ... you pointed me directly where I needed to go ... all I had to do was take out the session ans replace it with the row variable ... thank you thankyou ..I was smacking my head and just couldn't see it ...
No problem =)
Your code looked so clean and efficient that I thought it would be something simple like that.
I like to see clean code like you have there, keep it up.

Joe P
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.