How to call PHP Function From jQuery
getstudent('"+$("#classroom").val()+"')
I sure MySQL had 4 records about classroomid='c1'
But I can't show 4 records to selectbox student
In HTML
<select name="classroom" id="classroom" class="required"><option value="c1" selected>Room-1</option><option value="c2">Room-2</option></select>
In jQuery
$("#selectstudent").append("<tr><td><select name='student["+x+"]' id='student"+x+"'><?=getstudent('"+$("#classroom").val()+"')?></select>")</td></tr>").trigger('create');
In 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;
}
I only got "Select studentid,studentname From student Where classroomid='c1' Order By studentid
" And "0" in selectbox student
If I delete "Where classroomid='$roomid'
" from $query,It can show all data into selectbox student
I paste "Select studentid,studentname From student Where classroomid='c1' Order By studentid
" to querywindow of phpMyAdmin and run,It's show 4 records