Hi folks,
Am stuck again, please help 🙁
I have 2 tables:
'postings' - contains data for each posting.
'bids' - contains the bids for each posting in the postings table.
I am trying to code a page which displays the postings in a html table, I am having trouble during the first while loop to count the number of bids for each posting from the bids table.
This is what I have so far, it is FAR from right as it is echoing the number of bids the first posting has, but then echoing that same number for all other postings 🙁
// make the query to get the postings
$query = "SELECT posting_id, vehicle_type, vehicle_make, year, buyers_city, buyers_state, condition, category, DATE_FORMAT(expiry_date, '%e-%m-%y, %h:%i %p') as e_date FROM postings WHERE buyers_id=$_SESSION[buyers_id]";
// run the query
$result = @mysql_query ($query);
while($row=mysql_fetch_array($result))
{
// make the 2nd query to get the number of bids
$query2 = "SELECT bid_id, posting_id, sellers_id, price, status, DATE_FORMAT(date_of_bid, '%e-%m-%y, %h:%i %p') as bid_date FROM bids WHERE posting_id='11'";
// run the query
$result2 = @mysql_query ($query2);
// get the number of rows
$num = mysql_num_rows($result2);
echo '<tr>';
echo '<td class="row1" align="center" valign="middle" width="25%"><span class="gen">' . $row['category'] . '</span></td>';
echo '<td class="row1" align="center" valign="middle" width="15%"><span class="gen">' . $row['e_date'] . '</span></td>';
if ($num > 0) { // if it ran ok, display the records
echo "<td class=\"row1\" align=\"center\" valign=\"middle\" width=\"10%\"><span class=\"gen\">$num</span></td>";
} else {
echo '<td class="row1" align="center" valign="middle" width="10%"><span class="gen">0 bids</span></td>';
}
echo '</tr>';
}