werny Posted December 9, 2007 Share Posted December 9, 2007 what is the easiest way in an array, to break to the next line after say 10 values from a database? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted December 9, 2007 Share Posted December 9, 2007 Do you mean add a new line (<br />)/paragraph (<p></p>) after ten items have been pulled out from a database? If so then following should do it: $qry = 'YOUR QUERY HERE'; $result = mysql_query($qry); $i = 0; // Initiate the counter while($row = mysql_fetch_assoc($result)) { // echo your row(s) here // check to see if $i is less than 10, if it is increment counter by one, else echo a new line. if($i < 10) $i++; // increment counter by one else echo '<br />'; // echo new line if $i is not less than 10; } Quote Link to comment Share on other sites More sharing options...
werny Posted December 9, 2007 Author Share Posted December 9, 2007 well would that script work for every line, or could I just change to put everytime it break it resets $i as zero then recounts? Quote Link to comment Share on other sites More sharing options...
LuckY07 Posted December 9, 2007 Share Posted December 9, 2007 i'm not really following you. wildteen's code will record EVERY row using the while() loop. it goes to every row and returns ONLY what you tell it to, using the VALUES. you can then do as he said with the counter $i as he showed. so if you only want the first 10 values, well you have to see how you defined them, then have the query retrieve them, make sense? showing us some code would also help. 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.