derekshull Posted April 5, 2013 Share Posted April 5, 2013 I have a script that displays the States and the cities in that state where we have records. This is the code I had at first: $lookup = "SELECT state, city, count(city) as num FROM needs WHERE country IS NULL AND status='posted' GROUP BY state, city ORDER BY state, city"; if ($result = mysql_query($lookup)) { $num_rows = mysql_num_rows($result); echo "<table>"; $i = 1; $cols = 3; $prev = ''; while ($frows = mysql_fetch_array($result)) { $fcity = $frows['city']; $fstate = $frows['state']; $fcitycount = $frows['num']; // num is holding your count by city if ($fstate != $prev) { echo "<tr><td><h2>$fstate</h2></td>"; $prev = $fstate; } echo "<tr><td><a href='browseresults.php?city=$fcity&state=$fstate'>$fcity, $fstate ($fcitycount)</a></td></tr>"; } echo "</table>"; } When output comes out I want it to look like the following but it doesn't work: Arkansas Tennessee Missouri Searcy, AR (1) Bartlett, TN (1) St. Louis, MO (4) Little Rock, AR (4) Memphis, TN (3) Perry, MO (3) Benton, AR (2) Branson, MO (1) Shell, MO (2) Does anyone know how it can be done? After 5 hours and a stackflow post no one seems to know what's up. Quote Link to comment https://forums.phpfreaks.com/topic/276551-php-html-after-5-states-in-a-row-go-to-next-row/ Share on other sites More sharing options...
Jessica Posted April 5, 2013 Share Posted April 5, 2013 (edited) You need to increment $i, and then use modulus. if($i%3==0){ // new row }Edit: Actually, what? Your title says every 5 states, your example shows 3, but really it looks like you just need to do a new column every state. Edited April 5, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/276551-php-html-after-5-states-in-a-row-go-to-next-row/#findComment-1422999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.