ilovephp798 Posted August 5, 2014 Share Posted August 5, 2014 Hi, I would like to ask, how to display the while loop result 3 per row with the following code below: $startDate = strtotime($datefrom); $endDate = strtotime($dateto); $date = $startDate; while( $date <= $endDate) { echo "<input type='checkbox' name='date'>"; echo date('d-m-Y', $date) .' '; $date = strtotime('+1 day', $date); } Anyone can assist me on this? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/290280-display-while-loop-result-3-per-row/ Share on other sites More sharing options...
Ch0cu3r Posted August 5, 2014 Share Posted August 5, 2014 Have look at the examples shown in this thread. http://forums.phpfreaks.com/topic/11572-multi-column-results/ See if you can apply the logic demonstrated to your while loop Quote Link to comment https://forums.phpfreaks.com/topic/290280-display-while-loop-result-3-per-row/#findComment-1486880 Share on other sites More sharing options...
Barand Posted August 5, 2014 Share Posted August 5, 2014 I find floating divs easiest $datefrom = new DateTime('2014-07-01'); $dateto = new DateTime(); // today $dp = new DatePeriod($datefrom, new DateInterval('P1D'), $dateto); $i = 0; foreach ($dp as $date) { echo "<div style='width:120px; float:left'> <input type='checkbox' name='date[]' value='{$date->format('Y-m-d')}' /> {$date->format('d-m-Y')} </div>"; if (++$i%3 == 0) echo "<div style='clear:both'></div>"; } OUTPUTS Quote Link to comment https://forums.phpfreaks.com/topic/290280-display-while-loop-result-3-per-row/#findComment-1486883 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.