jesushax Posted March 30, 2009 Share Posted March 30, 2009 hi all below is my code it works fine apart from if the loop of rows ended on a number less than 6 at the moment i get three columsn fine then the last colum only has 3 <li></li>s in so its not putting the final, </ul> and </div> on it i cant think of how to check if there is less than 6 at the end without making it put a </ul></div> after every record anyone help? $SQL = mysql_query("SELECT * FROM tblTrades ORDER BY 'trades' DESC") or die(mysql_error()); $col = 1; $colMax = 6; while($list=mysql_fetch_array($SQL)) { if ($col == 1) { echo '<div class="columns">'."\n"; echo "<ul>\n"; } echo '<li>'.$list["trades"].'</li>'."\n"; if ($col == $colMax) { echo " </ul>\n"; echo " </div>\n"; $col = 1; } else { $col++; } if ($col > $colMax) { echo " </ul>\n"; echo " </div>\n"; } } Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 i think this will work <?php $SQL = mysql_query("SELECT * FROM tblTrades ORDER BY 'trades' DESC") or die(mysql_error()); $col = 1; $colMax = 6; while($list=mysql_fetch_array($SQL)) { if ($col == 1) { echo '<div class="columns">'."\n"; echo "<ul>\n"; } echo '<li>'.$list["trades"].'</li>'."\n"; if ($col == $colMax) { echo " </ul>\n"; echo " </div>\n"; $col = 1; } else { $col++; } } if ($col != $colMax && $col != 1) { echo " </ul>\n"; echo " </div>\n"; } Quote Link to comment Share on other sites More sharing options...
ober Posted March 30, 2009 Share Posted March 30, 2009 Put a statement outside of the while loop that checks to see if your current column is less than the column max. Also, why are you putting newlines after each of the elements? Browsers don't read newlines unless you're doing that strictly for the readability of the source (and I'm not even sure that works?). Quote Link to comment Share on other sites More sharing options...
jesushax Posted March 30, 2009 Author Share Posted March 30, 2009 That got it thanks yeah the linebreaks where for readability of the source cheers again Quote Link to comment 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.