Jump to content

[SOLVED] for looping issue


timmah1

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>

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.