Show checkbox values from database in PHP

后端 未结 4 1805
天命终不由人
天命终不由人 2021-01-26 19:43

In Database I have a column \'language\' which have values English, Arabic, Urdu respectively. Now, I am gett

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-26 20:31

    Try this:

    $lang = $pdo->prepare("SELECT `language` FROM admin_panel_languages WHERE user_id=:user_id");
    $lang->execute(array(":user_id"=>$user_id));
    $lang_spoken=$lang->fetchAll(PDO::FETCH_ASSOC);
    print_r($lang_spoken);
    
    $checkedEng = '';
    $checkedHindi = '';
    
    foreach($lang_spoken as $lang) {
        if (($lang['language'] == "English")) {
            $checkedEng = 'checked';
        } else if ($lang['language'] == "Hindi") {
            $checkedHindi = 'checked';
        }
    }
    
    
    
    
    

    ?>

    Though I haven't tested the above code, but I think this one should work for you.

提交回复
热议问题