Hi everyone,
I have the value of product size ($prodsize) stored in MySQL table in CSV format, such as “4,5,6”. On the update product page, I have checkbox listed all the possible sizes like this:
<INPUT TYPE=CHECKBOX name=“productsize” value=“3”>Size 3<BR>
<INPUT TYPE=CHECKBOX name=“productsize” value=“4”>Size 4<BR>
<INPUT TYPE=CHECKBOX name=“productsize” value=“5”>Size 5<BR>
<INPUT TYPE=CHECKBOX name=“productsize” value=“6”>Size 6<BR>
<INPUT TYPE=CHECKBOX name=“productsize” value=“7”>Size 7<BR>
If a product’s size is “4,5,6” before the update, what I want on the update page is Size 4, Size 5, Size 6 box is checked. I have no problem retrieve the value of $prodsize from the table, I tried the method below but doesn’t work.
<?php
$sizes = array($prodsize);
?>
<INPUT TYPE=CHECKBOX name="productsize" value="3" <?php if(in_array("3",$sizes)) {echo "checked='yes'";} ?>>Size 3<BR>
<INPUT TYPE=CHECKBOX name="productsize" value="4" <?php if(in_array("4",$sizes)) {echo "checked='yes'";} ?>>Size 4<BR>
<INPUT TYPE=CHECKBOX name="productsize" value="5" <?php if(in_array("5",$sizes)) {echo "checked='yes'";} ?>>Size 5<BR>
<INPUT TYPE=CHECKBOX name="productsize" value="6" <?php if(in_array("6",$sizes)) {echo "checked='yes'";} ?>>Size 6<BR>
<INPUT TYPE=CHECKBOX name="productsize" value="7" <?php if(in_array("7",$sizes)) {echo "checked='yes'";} ?>>Size 7<BR>
How to make it work in PHP?
Many thanks