rn14 Posted November 29, 2008 Share Posted November 29, 2008 Hi, <p><input type="checkbox" name="meal[]" value="<?php echo $row['id']; ?>" CHECKED/> The above is printed out as part of a loop. there are 7 checkboxes printed out each one being checked. However i still want the seven printed out but with only the first 5 checked. Could anybody help me with this? Thanks Quote Link to comment Share on other sites More sharing options...
ds111 Posted November 29, 2008 Share Posted November 29, 2008 here... <?php if($i =< 5) { echo'<p><input type="checkbox" name="meal[]" value="'.$row['id'].'" checked="checked"/>'; } else { echo'<p><input type="checkbox" name="meal[]" value="'.$row['id'].'" />'; } replace the $i variable with whatever other variable you are using that you add 1 at the end of the loop. Note i didnt test this code Quote Link to comment Share on other sites More sharing options...
rn14 Posted November 29, 2008 Author Share Posted November 29, 2008 Its part of a while loop so will I be able to work it like that. I have to still print out the 7 checkboxes but just with 5 selected while($row = mysql_fetch_array($result)) { $image = $row['image']; $title = $row['title']; $description = $row['text']; echo strip_tags($image, '<img>, <span>'); ?> <p><input type="checkbox" name="meal[]" value="<?php echo $row['id']; ?>" CHECKED/> What you think?? Quote Link to comment Share on other sites More sharing options...
rn14 Posted November 29, 2008 Author Share Posted November 29, 2008 Really tearing my hair out with this could anybody give me some help?? Thanks Quote Link to comment Share on other sites More sharing options...
rn14 Posted November 29, 2008 Author Share Posted November 29, 2008 Should this work???? <? if($rows <= 5) { echo'<p><input type="checkbox" name="meal[]" value="'.$row['id'].'" checked="checked"/>'; } else { echo'<p><input type="checkbox" name="meal[]" value="'.$row['id'].'" />'; } ?> Thanks Quote Link to comment Share on other sites More sharing options...
rn14 Posted November 30, 2008 Author Share Posted November 30, 2008 Any chance of anybody having a look at this??? Quote Link to comment Share on other sites More sharing options...
.josh Posted November 30, 2008 Share Posted November 30, 2008 I don't understand how you can work with a database and use a loop but fail to understand the concept of incrementing a variable, but whatever. <?php $x = 0; while(true) { $checked = ($x < 5)? "checked='checked'" : ""; echo "<p><input type='checkbox' name='meal[]' value='{$row['id']}' $checked/>"; $x++; } Quote Link to comment 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.