Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法根据数据库数据选择下拉选项_Php_Jquery_Mysql - Fatal编程技术网

Php 无法根据数据库数据选择下拉选项

Php 无法根据数据库数据选择下拉选项,php,jquery,mysql,Php,Jquery,Mysql,我有三张桌子 我需要从下拉列表中选择多个数据,并将该数据与表hotel_rooms中的hotel id列一起保存 如果下拉项已经在hotel_rooms表中,我需要选择该选项 我可以在下拉列表中列出数据。但我的问题是,没有选择酒店房间中已保存的数据 请检查所附的图片和给定的代码,并帮助我解决这个问题 hotel ----- id name address 42 taj delhi room ----- id title 1 suit 2 deluxe 4 standard

我有三张桌子

我需要从下拉列表中选择多个数据,并将该数据与表hotel_rooms中的hotel id列一起保存

如果下拉项已经在hotel_rooms表中,我需要选择该选项

我可以在下拉列表中列出数据。但我的问题是,没有选择酒店房间中已保存的数据

请检查所附的图片和给定的代码,并帮助我解决这个问题

hotel
-----
id name address
42   taj  delhi

room
-----
id title
1   suit
2   deluxe
4   standard

hotel_rooms
-----------
hotel_id  room_id
42         1
42         2
42         4
代码

萤火虫检验结果 当您有多个选择时,您必须执行以下操作

//take all saved it array to variable
var valArr = [101,102];
i = 0, size = valArr.length;
for(i; i < size; i++){
  $("#data").multiselect("widget").find(":checkbox[value='"+valArr[i]+"']").attr("checked","checked");
  $("#data option[value='" + valArr[i] + "']").attr("selected", 1);
  $("#data").multiselect("refresh");
}

这不应该也使用吗?您正在使用变量$find where is defined?您的$select2查询返回空结果,因为条件COUNT*>1您不认为它应该COUNT*>=1@samsamI建议确保您的条件为真-$emailToRecord==$row['id']?'选定的=选定的':;我想知道您是否在$emailToRecord和$row['id'].@sam中得到正确的结果请检查我的答案
<li class=" hotelrooms">
<label class="ui-corner-all" title="" for="ui-multiselect-0-option-0">
<input id="ui-multiselect-0-option-0" type="checkbox" title="" value="31" name="multiselect_0">
<span>rooms</span>
</label>
</li>
<li class=" hotelrooms">
<label class="ui-corner-all" title="" for="ui-multiselect-0-option-1">
<input id="ui-multiselect-0-option-1" type="checkbox" title="" value="30" name="multiselect_0">
<span>Dummy</span>
</label>
</li>
<li class=" hotelrooms">
<label class="ui-corner-all" title="" for="ui-multiselect-0-option-2">
<input id="ui-multiselect-0-option-2" type="checkbox" title="" value="29" name="multiselect_0">
<span>Tests</span>
</label>
</li>
<li class=" hotelrooms">
<label class="ui-corner-all" title="" for="ui-multiselect-0-option-3">
<input id="ui-multiselect-0-option-3" type="checkbox" title="" value="28" name="multiselect_0">
<span>Superior Zimmer Einzelnutzung</span>
</label>
</li>
//take all saved it array to variable
var valArr = [101,102];
i = 0, size = valArr.length;
for(i; i < size; i++){
  $("#data").multiselect("widget").find(":checkbox[value='"+valArr[i]+"']").attr("checked","checked");
  $("#data option[value='" + valArr[i] + "']").attr("selected", 1);
  $("#data").multiselect("refresh");
}