Jump to content

Recommended Posts

I have some info in the database that is like this

54,9741,95,1

 

I'm trying to pull that info out with explode.

Then, I'm trying to check it against check boxes, and if it equals the value, it checks the box.

 

It does this fine, but the problem is that it loops everything 9 times because there are 9 items.

Then it checks the appropriate boxes, but each group is looped.

 

I don't know how to avoid this.

 

Here is my code

<table width="100%" cellpadding="4" cellspacing="0">
    
    <?php
$medical = explode(',', $charts['medication']);
for($i = 0; $i < count($medical); $i++) { ?>
<tr>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],1))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="1">
Clomid</font></td>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],128))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="128">IVF Transfer</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],2))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="2">Estrogen</font></td>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],32))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="32">Metformin</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],256))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="256">FSH</font></td>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],16))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="16">Other Medications</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],512))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="512">Femara/Letrozole</font></td>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="8">Progesterone</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!(strcmp($medical[$i],4))) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="4">HCG</font></td>
<td colspan="2"> </td>
</tr>
<?php } ?>

</table>

 

How would I do this?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/141253-solved-for-looping-issue/
Share on other sites

Not sure I understand, because now it don't show that any were checked

<table width="100%" cellpadding="4" cellspacing="0">
    
<?php
$medical = explode(',', $charts['medication']);
?>
<tr>
<td colspan="2"><font size="2"><input <?php if (!in_array(1,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="1">
Clomid</font></td>
<td colspan="2"><font size="2"><input <?php if (!in_array(128,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="128">IVF Transfer</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!in_array(2,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="2">Estrogen</font></td>
<td colspan="2"><font size="2"><input <?php if (!in_array(32,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="32">Metformin</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!in_array(256,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="256">FSH</font></td>
<td colspan="2"><font size="2"><input <?php if (!in_array(16,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="16">Other Medications</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!in_array(512,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="512">Femara/Letrozole</font></td>
<td colspan="2"><font size="2"><input <?php if (!in_array(8,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="8">Progesterone</font></td>
</tr>
<td colspan="2"><font size="2"><input <?php if (!in_array(4,$medical)) {echo "checked=\"checked\"";} ?> type="checkbox" name="medication[]" value="4">HCG</font></td>
<td colspan="2"> </td>
</tr>


</table>

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.