如何从jQuery调用PHP函数
getstudent('"+$("#classroom").val()+"')
我确定MySQL有4条关于classroomid='c1'
但我无法向选择框学生显示4条记录
在HTML中
<select name="classroom" id="classroom" class="required"><option value="c1" selected>Room-1</option><option value="c2">Room-2</option></select>
在jQuery中
$("#selectstudent").append("<tr><td><select name='student["+x+"]' id='student"+x+"'><?=getstudent('"+$("#classroom").val()+"')?></select>")</td></tr>").trigger('create');
在PHP中
function getstudent($roomid){
$query = "Select studentid,studentname From student Where classroomid='$roomid' Order By studentid";
$sql=mysql_query($query);
if (mysql_num_rows($sql)){
while ($rs = mysql_fetch_assoc($sql)){
$str = $str."<option value='".$rs["studentid"]."'>".$rs["studentname"]."</option>";
}
}else{
$str="";
}
//test//
$str = $str."<option value=''>".$query."</option>";
$str = $str."<option value=''>".mysql_num_rows($sql)."</option>";
return $str;
}
我只得到&#34; Select studentid,studentname From student Where classroomid='c1' Order By studentid
&#34;并且&#34; 0&#34;在选择框学生
如果我删除&#34; Where classroomid='$roomid'
&#34;来自$ query,它可以将所有数据显示到selectbox student
我粘贴&#34; Select studentid,studentname From student Where classroomid='c1' Order By studentid
&#34;查询phpMyAdmin的窗口并运行,它显示4条记录