The code I posted was just a basic example. I have used this method to good success with ordered/unordered lists, complete table rows and so on. So long as you keep track of the city names changing you're all set.
For example, the following code is an extract of an existing script I have that displays a list of categorised Useful Links (see www.hickeyshikers.com/links.html) stored in a database table.
The script firstly collects all the categories, and displays these as quick links at the top of the page. Then, the links in each category are printed, with title (as a link to the destination URL) and description of the destination site.
$currentCategory = 0;
$catList = "Quick Links:<br>";
$pageContent = "<table width='500' align='left' valign='top' border='0' cellpadding='2' cellspacing='0'>";
while($row=mysql_fetch_array($res)){
$linkID = $row['id'];
$linkCat = $row['linkCategory'];
if($linkCat!=$currentCategory){
// new category, so print heading
$currentCategoryName = getFieldByID("linkcats","linkcatsname","id",$linkCat);
$pageContent .= "<tr>
<td class='maintext'colspan='2'><a name='cat$linkCat' class='usefullink'>$currentCategoryName</a></td>
</tr>";
$catList .= "<a href='#cat$linkCat' class='usefullink'>$currentCategoryName</a><br>";
$currentCategory = $linkCat;
}
$linkURL = stripslashes($row['linkURL']);
$linkTitle = stripslashes($row['linkTitle']);
$linkDescription = convertPseudo($row['linkDescription']);
$separator = "<tr>
<td width='20'><br></td><td><br></td>
</tr>";
if($linkTitle==""){
$linkTitle = $linkURL;
}
$pageContent .= "<tr>
<td width='20'><br></td>
<td class='maintext'><a href='$linkURL' class='usefullink' target='new$linkID'>$linkTitle</a></td>
</tr>
<tr>
<td width='20'><br></td>
<td class='maintext'>$linkDescription</td>
</tr>" . $separator;
}
$pageContent .= "</table>";
$catList .= "<hr width='200' align='left' color='#455A58' size='1' noshade><br><br>";
// print the final results:
echo("$catList<br><br>$pageContent");
As you can see, this code actually keeps a running store of two lists. Sorry it's not commented, but there's nothing too complex going on.
Note - the names of the link categories are stored in a different database table. The 'getFieldByID()' function simply gets the category name based on its id.
The 'convertPseudo()# function parses custom tags (similar to this forums') into true HTML.
With a little modification, you can get this style of coding to generate almost any type of printed output.
Hope that's clearer...
Slick