Aegist Posted October 11, 2007 Share Posted October 11, 2007 I tried searching for this before posting, but I'm not even sure what to search for. Obviously I couldn't find what I was looking for, so hopefully it isn't too stupid a question (I am very noob with PHP still). I have a lot of data that I am pulling from a MySQL DB and displaying it in a crude table. Is there anyway to start the while loop (pulling up say, 80 results), and direct it to print a row of headings every 20 results? So that way the users still know what they are looking at even when scrolled down to the bottom. Or is this the wrong question to ask? Thanks for any help! Shane Quote Link to comment https://forums.phpfreaks.com/topic/72744-interrupting-long-while-loops-with-heading-rows/ Share on other sites More sharing options...
Cagecrawler Posted October 11, 2007 Share Posted October 11, 2007 You can do it 2 ways. Either limit the sql query to 20 results and have multiple queries, or have some sort of counter that increases each time the loop is executed. When it gets to 20 (or a multiple thereof), include the headings. <?php $i = 0; while($array = mysql_fetch_array($query)) { if(fmod($i,20) == 0) { //echo heading } //echo current line } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72744-interrupting-long-while-loops-with-heading-rows/#findComment-366868 Share on other sites More sharing options...
harristweed Posted October 11, 2007 Share Posted October 11, 2007 I think a better way is to use CSS look at http://www.starvillasjavea.com/rental_villa_availability.php Find how to do it here http://www.cssplay.co.uk/layouts/frame.html Quote Link to comment https://forums.phpfreaks.com/topic/72744-interrupting-long-while-loops-with-heading-rows/#findComment-366870 Share on other sites More sharing options...
roopurt18 Posted October 11, 2007 Share Posted October 11, 2007 You can use regular mod operator instead of a function call: if( $i % 20 == 0 ){ // echo heading } Also, don't forget to increment $i each time through the loop. Quote Link to comment https://forums.phpfreaks.com/topic/72744-interrupting-long-while-loops-with-heading-rows/#findComment-366871 Share on other sites More sharing options...
Aegist Posted October 11, 2007 Author Share Posted October 11, 2007 Thanks, I'll give that a try! Quote Link to comment https://forums.phpfreaks.com/topic/72744-interrupting-long-while-loops-with-heading-rows/#findComment-366872 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.