0

I'm updating some countries values into db table. All countries fetch from TBL_COUNTRY table. Then few countries store to another table. I'm using implode function to store multiple values. it works fine. it stored like this in my db table Afghanistan,Argentina,Austria,Bangladesh.

I have tried this code

           <?php
                $exp_str = explode(',', $model_availability);
                foreach($exp_str as $get_str)
                {
                    echo $get_str;
                }
            ?>

This above code return this output AfghanistanArgentinaAustriaBangladesh

How do I put tick on the checkbox based on this value?

            <?php
                $sql = "SELECT * FROM ".TBL_COUNTRY." ORDER BY country_name ASC";
                $exe = mysql_query($sql, $CN);
                while($r = mysql_fetch_array($exe))
                {   
            ?>
            <input type="checkbox" name="model_availability[]" value="<?=$r['country_name']?>" id="<?=$r['country_name']?>" />
            <label for="<?=$r['country_name']?>"><?=$r['country_name']?></label>
            <?php } ?>

2 Answers 2

1
<input type="checkbox" name="model_availability[]" value="<?=$r['country_name']?>" id="<?=$r['country_name']?>"<?=(in_array($r['country_name'],$model_availability)?" checked":"")?> />
Sign up to request clarification or add additional context in comments.

Comments

0

//In the input box just add a checked attribute, you will get.

 " id="" checked = "true" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.