Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have two tables, one called country with cid, country_name and another called city with cityid, city_name.
I want to print out the contents of these, categorized by country, like so:
France
- Paris
- Nice
- Cannes
England
- London
- Leeds
- Birmingham
Netherlands
- Amstedam
- etc....
To do this I use the following code:Code: Select all
$query = "SELECT co.country, ci.city FROM country co, city ci WHERE ci.cid=co.cid ORDER BY country";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
if($previous_country!=$row['country_name'])
{
echo '<br><b>'.$row['country_name'].'</b><br>';
$previous_country=$row['country_name'];
}
echo $row['city_name'].'<br>';
}http://www.specialinvestor.com/temp.php
Neater, yet much more difficult (for me) to manage.
In other words, put the contents in this HTML:
Code: Select all
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="#CCCCCC"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#F4F4FF"><table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="80%" align="left" valign="top">COUNTRY 1 </td>
<td width="20%" align="right" valign="top">FLAG</td>
</tr>
<tr>
<td align="left" valign="top"><ul>
<li>City 1</li>
<li>City 2</li>
<li>City ... </li>
</ul></td>
<td align="right" valign="top">&nbsp;</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>Can anyone help me with this?
Cheers
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]