Cultureshock Posted November 12, 2009 Share Posted November 12, 2009 If I have a while statement echo all the applicable data in a mysql table, how can I insert everything after every four rows, such as a div? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 $counter = 0; while(condition){ if ($counter % 4 = 0){ //do something ever 4 } //do other stuff } second post like this today Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 13, 2009 Author Share Posted November 13, 2009 Thanks. Sorry I didn't look. I was kind of busy coding other aspects of my project. Thanks again. Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 13, 2009 Author Share Posted November 13, 2009 Sorry, but it didn't work. It posted *do something every 4* before each set of data, not every four sets of data. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 13, 2009 Share Posted November 13, 2009 oops $counter = 0; while(condition){ if ($counter % 4 == 0){ //do something ever 4 } //do other stuff } Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 13, 2009 Author Share Posted November 13, 2009 Yeah, I fixed that earlier. It didn't work. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 13, 2009 Share Posted November 13, 2009 same code works perfectly fine for me? did you update the counter? //while loop stuff above $counter++; }//end while sorry forgot to put that, but thought it was obvious btw you may want to set $counter to 1 instead of 0. 0%4 is 0, so the first time the loop runs it will do the //do something every 4 code Quote Link to comment Share on other sites More sharing options...
sasa Posted November 13, 2009 Share Posted November 13, 2009 <?php $counter = 0; while ($counter<11) { if ($counter % 4 == 0){ echo "<div>\n"; } $counter++; echo "\t$counter\n"; if ($counter % 4 == 0){ echo "</div\n"; } } if ($counter % 4 != 0){ echo "</div\n"; } ?> Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 13, 2009 Author Share Posted November 13, 2009 All that did was echo numbers 1-11 before each row like this: 1 2 3 4 5 6 7 8 9 10 11 *data* Am I supposed to be changing something to match something in my mysql? MySQL version 5.0.85 PHP version 5.2.11 Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 16, 2009 Author Share Posted November 16, 2009 Does anyone know how to? Quote Link to comment Share on other sites More sharing options...
sasa Posted November 16, 2009 Share Posted November 16, 2009 <?php $counter = 0; while (your statement here) { if ($counter % 4 == 0){ echo "<div>\n"; } $counter++; //echo "\t$counter\n"; echo "your data"; if ($counter % 4 == 0){ echo "</div>\n"; } } if ($counter % 4 != 0){ echo "</div>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
Cultureshock Posted November 16, 2009 Author Share Posted November 16, 2009 It worked Thanks. 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.