Nesting an If Statement Within a While Loop
Posted: Sat Jun 28, 2008 6:05 pm
Thanks in advance for any help.....
I am doing a real estate site and on my "ShowListings.php" page I want to include a line of text if my "OpenHouse" variable value is true for a given record. The problem is that with my code below the conditional text does not loop with each record if the value is true for more than one, but instead it just repeats the given amount of times before my loop starts (at the top of the page). Can somebody help me set up the loop correctly (lines 25-28 below show contain the conditional text)?
I am doing a real estate site and on my "ShowListings.php" page I want to include a line of text if my "OpenHouse" variable value is true for a given record. The problem is that with my code below the conditional text does not loop with each record if the value is true for more than one, but instead it just repeats the given amount of times before my loop starts (at the top of the page). Can somebody help me set up the loop correctly (lines 25-28 below show contain the conditional text)?
Code: Select all
<table align="center">
<?PHP
// This query returns partial information for listings that are both not voided and not sold
$ListingsQuery = "select l.ListingID as ListID, l.Image, l.tbType_TypeID, t.TypeName, b.Borough, l.City, l.Price, l.Rooms, l.OpenHouse
from tbListing l
join tbBorough b on b.BoroughID = l.tbBorough_BoroughID
join tbType t on t.TypeID = l.tbType_TypeID
where l.Void = '0'
and l.Sold = '0'";
$FindListings = mysql_query($ListingsQuery);
while ($ReturnedListings = mysql_fetch_assoc($FindListings))
{
$Image = $ReturnedListings['Image'];
$ListingID = $ReturnedListings['ListID'];
$TypeName = $ReturnedListings['TypeName'];
$Borough = $ReturnedListings['Borough'];
$City = $ReturnedListings['City'];
$Price = $ReturnedListings['Price'];
$Rooms = $ReturnedListings['Rooms'];
$OpenHouse = $ReturnedListings['OpenHouse'];
if ($OpenHouse == "1")
{
echo "<p align=\"center\">Open House Scheduled</p>";
}
echo "<tr><td colspan=\"2\">" . "<a href=\"ListingInfo.php?ListingID=$ListingID\"><img src=\"$Image\" border=\"0\"></a>" . "</td></tr>";
echo "<tr><td>ListingID:</td><td><a href=\"ListingInfo.php?ListingID=$ListingID\">$ListingID</a></td></tr>";
echo "<tr><td>Type:</td><td>$TypeName</td></tr>";
echo "<tr><td>Borough:</td><td>$Borough</td></tr>";
echo "<tr><td>City:</td><td>$City</td></tr>";
echo "<tr><td>Rooms:</td><td>$Rooms</td></tr>";
echo "<tr><td>Price:</td><td>" . "$" . number_format($Price, 2) . "</td></tr>";
echo "<tr><td height=\"25px\"> </td></tr>";
}
?>
</table>