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?
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
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.