Forum Moderators: coopster
so it liiks like this:
Boston
- client #1
- client #3
Miami
- client #4
New York
- client #2
i thought this would work but nothing is displayed, any ideas on what is wrong?
<?
$DBhost = "$DBhost";
$DBuser = "$DBuser";
$DBpass = "$DBpass";
$DBName = "$DBName";
$table = "$table";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sql = "SELECT *
FROM $table
ORDER BY city
ASC, name";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
echo "<TABLE align=\"left\" cellspacing=\"0\" cellpadding=\"0\">";
echo "<ul>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($current_city!= $row['city']){ echo '<li>'.$row['city'].'<ul>'; }
echo '<li>'.$row['name'].'</li>'; // whatever here
if ($current_city!= $row['city']){ echo '</ul></li>'; $current_city = $row['city']; }
}
echo "</ul>\n";
echo "</TABLE>";
mysql_free_result($result);
?>
If that doesn't yield any results, try setting error_reporting(E_ALL); at the top of the script and remove the @ from your select_db line to see what all your errors are - you should get at least one notice about $current_city not being defined on the first run through your loop.
After you've got wrinkles ironed out, you might want to experiment with GROUP BY city.