Let me explain in more details:
Now I have a drop down menu showing the classname. The above php+javascript code mean to create the corresponding student name list of the corresponding selected class.
class no student_name
1 Kelvin
1 Martin
2 Jean
2 Louis
3 Mary
3 Sisi
var selected_class_no is the class no that just selected by the user. Then with this number, I compare it with DB (all data has all been downloaded when the page is loaded).
for ($i=0;$i<$total_student;$i++) {
$db_class_no = $arr[$i]['class_no'];
echo "if (selected_class_no == '$db_class_no')\n";
echo "{\n";
$db_student_name[] = $arr[$i]['student_name'];
echo "alert ('$i');\n";
echo "}\n";
}
This script is to compare the user-selected class_no with DB data, if the user select "1", then Kevlin, Martin would push into a new array and then display. But when i echo $i, it does show if-statment only execute twice, but when i echo count($db_student_name), this array has contained all six student name)