php loops

doctorbill
doctorbill used Ask the Experts™
on
I have the following php loop which is working fine on my page:
-------------------------------------------
<?php
                $i = "1";      
                      
        do {
              ?>
      <input type="checkbox" name="pa_it<?php echo $row_orders['ID']; ?>_<?php echo $i; ?>" value="1" class="flip" checked="checked"  />&nbsp;<?php echo $i; ?>

      <?php $i++;} while ($i <= 21 ) ?>
-------------------------------------------

What I need is the following:
1. to introduce a <br> tag when $i is 7 and 14
2. to only check the boxes when a variable is set. I haven't as yet decided on this variable but if someone could give me an idea of what to do I would be very grateful

Bill
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
For adding the <br>


if ($i==7 || $i==14) echo "<br>";

Open in new window


For checking your box

value="1" class="flip" <?php if (isset($myVar)) echo "checked='checked'"; ?>  />

Open in new window

Commented:
Try this:

<?php 
	$i = "1";      
	do { 
		if (($i == 7)||($i == 14)) {
			echo "<br>";
		}
		$box_checked = true; // some variable evaluation here
?>
	<input type="checkbox" name="pa_it<?php echo $row_orders['ID']; ?>_<?php echo $i; ?>" value="1" class="flip" <?php
	echo ($box_checked?'checked="checked"':'');?>  />&nbsp;<?php echo $i; ?>
<?php
		$i++;
	} while ($i <= 21 )
?>

Open in new window

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial