function LoadClass() { $db = new DB_Connect(); $major_id = (string) $_POST['major_id']; $statement = 'select * from class where state = 1 and major_id=:major_id'; $result = $db->prepare($statement); $result->execute(array(':major_id' => $major_id)); $index = 0; $ret = ""; while ($row = $result->fetch()) { $element = new classes(); $element->setVal($row['class_id'], $row['class_name']); $ret[$index++] = $element; } echo json_encode($ret); }