forcom Posted June 6, 2009 Share Posted June 6, 2009 I have 50 states and I want my loop display 5 columns. right now my loop displays all 50 states in one column. I setup a table but I don`t know how to echo </td></tr><tr><td> every ten states in the loop. I am trying to get it to do 1 continue 2 7 3 8 4 9 5 etc. 6 break echo </td></tr><tr><td> Quote Link to comment https://forums.phpfreaks.com/topic/161209-need-help-with-loop-rows-and-columns/ Share on other sites More sharing options...
Maq Posted June 6, 2009 Share Posted June 6, 2009 Can you post the relevant code? You said you want to display every 10 rows, yet your example does not exemplify this. You have to use the modulus (%) operator in your while loop to check if the row count is divisible by 10 (every 10 rows). NOTE - Is there a reason you posted in the Framworks section? If not, I can move this to the more popular, "PHP Help" for additional help. Quote Link to comment https://forums.phpfreaks.com/topic/161209-need-help-with-loop-rows-and-columns/#findComment-850637 Share on other sites More sharing options...
forcom Posted June 7, 2009 Author Share Posted June 7, 2009 Sorry about the example it would have been too much typing. You can move it to help. $ctryfrom = "SELECT DISTINCT country FROM table"; $ctry = mysql_query($ctryfrom); while($row = mysql_fetch_assoc($ctry)){ $countrynames = $row['country']; echo '<table><tr><td>'; echo "$countrynames"; //I want to echo </td></tr><tr><td> to add another column in the table. How can I set it to echo } Quote Link to comment https://forums.phpfreaks.com/topic/161209-need-help-with-loop-rows-and-columns/#findComment-850747 Share on other sites More sharing options...
Maq Posted June 8, 2009 Share Posted June 8, 2009 Here's what you have to do: - Put your table tags outside the while loop. - You need to use the modulus operator (%) to see if the total number of columns is divisible by 10 (every 10) and create a new row. Quote Link to comment https://forums.phpfreaks.com/topic/161209-need-help-with-loop-rows-and-columns/#findComment-851525 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.