我正试图用php编写一个jquery函数,但该函数在编写到一半时停止了jquery函数的编写。当我启动while循环时,它似乎会导致内部服务器错误500
function loadSchedule() {
$id = $_SESSION['loginID'];
//query stuffs that works
$conn = getCon();
$res = $conn->query($qry);
echo "$(document).ready(function() {"
."$('#schedule').fullCalendar({"
." header: {"
." left: '',"
." center: '',"
." right: ''"
."},"
."defaultView: 'agendaWeek',"
."editable: false,"
."allDaySlot: false,"
."eventLimit: true," // allow "more" link when too many events
."events: [";
//problem starts here
while($rows = $res->fetch_assoc()){
foreach (explode(',', $rows['DOW']) as $val){
echo '{'
.'title:"'.$rows['Course_code'].' '.$rows['number'].'",'
.'start:"'.$rows['start'].'",'
.'end: "'.$rows['end'].'",'
.'dow: ['.getDayStr($val).'] '
.'},';
}
}
echo "]});});";
每当我注释掉while循环时,它就会工作,但除此之外它就会失败。如果我把它单独放在一个文件中,它可以很好地工作,但由于某种原因,它在放入脚本标记时失败了。
我预计您的SQL查询中会出现错误。如果查询失败,while($rows = $res->fetch_assoc())
将出现错误,因为$res
不是对象。您可以通过用if (!$res) die('query failed '.$conn->error);
替换while循环来检查这一点