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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.