1

I have few check boxes which users can select..inside a form..I'm sending all the checked check boxes to database and saving them by imploding ','..

Then again in html i'm exploding "," and getting data..But now i want to keep the check boxes which are already checked..How can i do that..I have tried following..

$chkw = $works;
$chkecked = explode(',',$chkw);


<input name="work[]" value="doctor" type="checkbox" <?php echo $chkecked [0] == 'doctor' ? 'checked="checked"':'' ?>>

But this way it is wrong..

Thank you!

2
  • Are you sure that $chkecked[0] == 'doctor' evaluates to true? Commented May 4, 2015 at 5:45
  • No that is the problem..it can change..not static @Darren Commented May 4, 2015 at 5:46

2 Answers 2

4

Please try this one

<?php if(in_array('doctor',$chkecked)){ ?> checked="checked" <?php } ?>
Sign up to request clarification or add additional context in comments.

Comments

-1

you have to use curl instead file_get_content and then use binary transfer such as

function grab_image($url,$saveto)
{

    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    $raw=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($saveto)){
        unlink($saveto);
    }
    $fp = fopen($saveto,'x');
    fwrite($fp, $raw);
    fclose($fp);
}

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.