• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

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>
<?php
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";

 next($bids);
}
?>
0
koochy
Asked:
koochy
  • 2
  • 2
1 Solution
 
BogoJokerCommented:
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
0
 
koochyAuthor Commented:
I need to pick the pedigree information based on each horse so the horse id from the first query.
0
 
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 ...
0
 
BogoJokerCommented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now