Jump to content

display while loop result 3 per row


ilovephp798

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/290280-display-while-loop-result-3-per-row/
Share on other sites

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

 

post-3105-0-77912300-1407253620_thumb.png

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.