I'm trying to display all the cities within a given county from my (zip code) DB. The code below IS working, however, the only issue is that in certain areas it will display the same city multiple times. For example, in a King County, WA it will display Seattle like 10+ times. I know it's because it's loaded into my DB multiple times because it has multiple zip codes, but is there a command that will not allow it to display duplicates? Here is the code that i have: <?php $abbr = $_GET['state']; $countyurl = $_GET['countyurl']; include 'config.php'; include 'opendb.php'; $query = "SELECT city, cityurl, county FROM demographic WHERE abbr='$abbr' AND countyurl='$countyurl'"; $result = mysql_query($query); echo "<strong>$county cities:</strong> <br>"; while(list($city,$cityurl)= mysql_fetch_row($result)) { echo "<a href=\"/city/$abbr-$countyurl-$cityurl.html\">$city</a> | "; } include 'closedb.php'; ?> PHP: THANK YOU
that's great thanks!!! One more thing... Is there a way that I can get this to list in a table with 3 columns, equally spread out? For example, if King County had a total of 17 cities I could get it to display 6, 6, & 5 in each column?
yes, use 3 different queries to be shown in 3 colums with 6 max. It should be in format LIMIT start, offset each column showing 10 rows. LIMIT 0,10 LIMIT 10,10 LIMIT 20,10
You can use this one <table> <tr> <? $incr=0; while($rs=mysql_fetch_array($query); { ?> <td>Records goes here.</td> <?php $incr++; if ($incr > 6; { echo "</tr><tr>"; $incr=0; } } ?>
Don't both of these scripts assume I know the number of cities? The 6,6,5 was just an example. The number will vary.
you could do this then <table> <tr> <? $incr=0; while($rs=mysql_fetch_array($query); { ?> <td>Records goes here.</td> <?php $incr++; if ($incr > ($totalrows / 3); { echo "</tr><tr>"; $incr=0; } } ?>