我有以下代碼。我想要根據數據庫值檢查複選框。當我在按鈕被選中時多次獲得按鈕組的同時編寫代碼時,無論如何,我都會檢查正確的按鈕。當代碼不在時,我得到警告:in_array()期望參數2是數組,空給出。我能做什麼 ?檢查數據庫值的複選框php
<?php
$query=" select description from doors
where id_doors IN
(select doors_id_doors from access_rights
where users_rfidcode='".$result['rfidcode']."'); ";
$resultt=$conn->query($query);
while($row=$resultt->fetch_assoc()){}
//in_array()check if value is in array
if(in_array("SW1",$row))echo '<input type="checkbox" name="chk[]" value="SW1" checked >SW1'; else echo '<input type="checkbox" name="chk[]" value="SW1" >SW1';
if(in_array("SW2",$row))echo '<input type="checkbox" name="chk[]" value="SW2" checked >SW2'; else echo '<input type="checkbox" name="chk[]" value="SW2" >SW2';
if(in_array("SW3",$row))echo '<input type="checkbox" name="chk[]" value="SW3" checked >SW3'; else echo '<input type="checkbox" name="chk[]" value="SW3" >SW3';
if(in_array("PR1",$row))echo '<input type="checkbox" name="chk[]" value="PR1" checked >PR1'; else echo '<input type="checkbox" name="chk[]" value="PR1" >PR1';
if(in_array("PR2",$row))echo '<input type="checkbox" name="chk[]" value="PR2" checked >PR2'; else echo '<input type="checkbox" name="chk[]" value="PR2" >PR2';
?>
誰能幫助我請? – Iris
您的連接信息? – Thamilan
$ conn = new mysqli($ servername,$ username,$ password,$ dbName); – Iris