Sorting a query by a field
Posted: Fri Mar 25, 2005 4:33 pm
I have 4 fields in a mysql table: id, area, address, details. I want to call the address and details, but display them in rows seperated, grouped and labeled by their respective Area. ie:
Can this be done? Here is my code thus far:
feyd | Please review how to post code using
Code: Select all
Address Details
Area 1
address 123 my st details blah bla
address 124 my st details blah bla
address 125 my st details blah bla
Area 2
address 127 my st details blah bla
address 128 my st details blah bla
address 129 my st details blah blaCode: Select all
<td colspan="3">
<?php
mysql_connect("xxxx","xxxx","xxxx");
mysql_select_db("xxxx");
echo ("<table width=740 border=1 cellpadding=1 cellspacing=1 >
<tr>
<td width=50%><b>Address</b></td>
<td width=50%><b>Details</b></td>
</tr>");
$sql = mysql_query("SELECT address, details FROM openhouse") or die ( mysql_error() );
while ($row = mysql_fetch_array($sql)) {
echo "<TR>"."<TD>".$row['address']."</TD>"."<TD>".$row['details']."</TD>";
}
echo "</TABLE>";
?></td>feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]