while loop is acting up :(
Posted: Wed Jun 25, 2008 8:07 pm
This is part to a dynamic page I made. It retrieves information from a database and then displays it. It retrieves communitys and then it retrieves the listings and puts each listing it pulls with the community it belongs to. The way it should display in a simplified format is below :
Community 1
<table starts>
<tr>
<td>Listing 1</td>
<td>Listing 2</td>
</tr>
</table ends>
Community 2
<table starts>
<tr>
<td>Listing 1</td>
<td>Listing 2</td>
</tr>
</table ends>
etc...
But it is doing..
Community 1
<table starts>
<tr>
<td>Listing 1</td>
</tr>
</table ends>
<table starts>
<tr>
<td>Listing 2</td>
</tr>
</table ends>
Community 2
<table starts>
<tr>
<td>Listing 1</td>
</tr>
</table ends>
<table starts>
<tr>
<td>Listing 2</td>
</tr>
</table ends>
I know it is doing this because the is inside of the while(); loop. But I can't figure out how to make it put the </table> after it is done echoing all the listings for a community. Any help? I hope I have been specific enough. Thanks!
Also, you can view the live script here...http://www.tristonehomes.com/inventory.php
Community 1
<table starts>
<tr>
<td>Listing 1</td>
<td>Listing 2</td>
</tr>
</table ends>
Community 2
<table starts>
<tr>
<td>Listing 1</td>
<td>Listing 2</td>
</tr>
</table ends>
etc...
But it is doing..
Community 1
<table starts>
<tr>
<td>Listing 1</td>
</tr>
</table ends>
<table starts>
<tr>
<td>Listing 2</td>
</tr>
</table ends>
Community 2
<table starts>
<tr>
<td>Listing 1</td>
</tr>
</table ends>
<table starts>
<tr>
<td>Listing 2</td>
</tr>
</table ends>
I know it is doing this because the
Code: Select all
echo '</table>';Also, you can view the live script here...http://www.tristonehomes.com/inventory.php
Code: Select all
while($row = mysql_fetch_array($result)) {
if($row['name'] != $current_community) {
$current_community = $row['name'];
echo('
<br>
<span class="community_title">'.ucfirst($current_community).'</span> <span class="location">'.ucfirst($row['c_city']).', '.ucfirst($row['c_state']).'</span>
<div class="divider"></div>
<span class="general_info">Price Range:</span> <span class="general_values">'.ucfirst($row['c_price_range']).'</span><span class="general_info">Phone:</span> <span class="general_values">'.$row['c_phone'].'</span><span class="general_info">Email:</span> <a href="mailto:'.$row['c_email'].'" class="email_link">'.$row['c_email'].'</a>
<div class="general_links_container">
<a href="community_features/'.$row['c_features'].'" class="general_links">Standard Features</a> | <a href="view_inventory.php?community_id='.$row['c_id'].'" class="general_links">View Current Inventory</a> | <a href="directions/'.$row['c_directions'].'" class="general_links">Community Details / Directions</a>
</div>
<span class="general_info">Community Summary</span>
<br />
<span class="community_summary">'.ucfirst($row['c_description']).'</span>
<div class="divider"></div>
<span class="floorplan_title">Floorplans</span> <span class="general_info">click on plan name for details</span>
<br />
<table border="0" cellspacing="0" cellpadding="0">
');
$tracker = 0;
}
$title = strtolower($row['title']);
$tracker = 1 - $tracker;
echo '<tr class="row'.$tracker.'"><td class="cell_spacing"><a href="view_listing.php?listing_number='.$row['l_id'].'" class="specfic_info">'.ucfirst($title).'</a></td>';
echo '<td class="cell_spacing"><span class="specfic_info">Square Footage : '.ucfirst($row['l_sq_ft']).'</span><br></td>';
echo '<td class="cell_spacing"><span class="specfic_info">Base Price : $'.ucfirst($row['l_price']).'</span><br></td></tr>';
echo '</table>';
}