主题:php mysql求助
.....
$conditions = "1";
$conditions .= ($classid != '' && $classid != 0) ?
" AND FIND_IN_SET ('".$classid."',schedule.class_id)" : NULL;
......
$sql = "SELECT schedule.*,teacher.teacher_name,course.course_name, room.room_name
FROM ". SCHEDULE_TABLE ." schedule,". TEACHER_TABLE ." teacher,". COURSE_TABLE ." course, ". ROOM_TABLE ." room
WHERE ($conditions)
AND (schedule.teacher_id=teacher.teacher_id)
AND (schedule.course_id=course.course_id)
AND (schedule.room_id=room.room_id)
ORDER BY schedule.date_id LIMIT $start,$per_page";
echo $sql;
$count_sql = "SELECT schedule.*,teacher.teacher_name,course.course_name, room.room_name
FROM ". SCHEDULE_TABLE ." schedule,". TEACHER_TABLE ." teacher,". COURSE_TABLE ." course, ". ROOM_TABLE ." room
WHERE ($conditions)
AND (schedule.teacher_id=teacher.teacher_id)
AND (schedule.course_id=course.course_id)
AND (schedule.room_id=room.room_id) ";
echo $count_sql;
$total_num = 0;
$count_query = mysql_query($count_sql);
while($count_res = mysql_fetch_array($count_query)) {
$total_num ++;
}
//echo " 共计".$total_num."次课。";
if(!$total_num) {$tj="<br><br>经查询,没有安排!"; echo $tj;}
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
$i++;
运行后出错:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 155
经查询,没有安排!
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 161
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 202
经检查发现:
1、$total_num 一直为0
2、echo $sql和 echo $count_sql 显示的sql在mysql管理里直接能执行,查询的结果也正常。
3、$conditions没被取得 " AND FIND_IN_SET ('".$classid."',schedule.class_id)" 进运行全正常。
请大家帮我看看这么回事?
$conditions = "1";
$conditions .= ($classid != '' && $classid != 0) ?
" AND FIND_IN_SET ('".$classid."',schedule.class_id)" : NULL;
......
$sql = "SELECT schedule.*,teacher.teacher_name,course.course_name, room.room_name
FROM ". SCHEDULE_TABLE ." schedule,". TEACHER_TABLE ." teacher,". COURSE_TABLE ." course, ". ROOM_TABLE ." room
WHERE ($conditions)
AND (schedule.teacher_id=teacher.teacher_id)
AND (schedule.course_id=course.course_id)
AND (schedule.room_id=room.room_id)
ORDER BY schedule.date_id LIMIT $start,$per_page";
echo $sql;
$count_sql = "SELECT schedule.*,teacher.teacher_name,course.course_name, room.room_name
FROM ". SCHEDULE_TABLE ." schedule,". TEACHER_TABLE ." teacher,". COURSE_TABLE ." course, ". ROOM_TABLE ." room
WHERE ($conditions)
AND (schedule.teacher_id=teacher.teacher_id)
AND (schedule.course_id=course.course_id)
AND (schedule.room_id=room.room_id) ";
echo $count_sql;
$total_num = 0;
$count_query = mysql_query($count_sql);
while($count_res = mysql_fetch_array($count_query)) {
$total_num ++;
}
//echo " 共计".$total_num."次课。";
if(!$total_num) {$tj="<br><br>经查询,没有安排!"; echo $tj;}
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
$i++;
运行后出错:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 155
经查询,没有安排!
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 161
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in D:\wwwroot\kebiao\index.php on line 202
经检查发现:
1、$total_num 一直为0
2、echo $sql和 echo $count_sql 显示的sql在mysql管理里直接能执行,查询的结果也正常。
3、$conditions没被取得 " AND FIND_IN_SET ('".$classid."',schedule.class_id)" 进运行全正常。
请大家帮我看看这么回事?