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? Link to comment https://forums.phpfreaks.com/topic/80881-going-to-a-new-line-in-an-array/ 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; } Link to comment https://forums.phpfreaks.com/topic/80881-going-to-a-new-line-in-an-array/#findComment-410331 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? Link to comment https://forums.phpfreaks.com/topic/80881-going-to-a-new-line-in-an-array/#findComment-410359 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. Link to comment https://forums.phpfreaks.com/topic/80881-going-to-a-new-line-in-an-array/#findComment-410474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.