Home >Backend Development >PHP Tutorial > SQL语句写法的有关问题

SQL语句写法的有关问题

WBOY
WBOYOriginal
2016-06-13 13:29:491136browse

SQL语句写法的问题
$search1 = "SELECT classroom_id,building_id FROM use2 
  WHERE (time = '{$time}')
  AND (building_id = '{$building_id}')
  AND (lesson_id LIKE '$lesson_id')";

$result1 = mysql_query($search1, $con);

 $row = mysql_fetch_array($result1);
  $search2 = "SELECT * FROM classroom2
  WHERE (building_id = '{$building_id}')
  AND * NOT IN
  (SELECT * FROM classroom2
  WHERE (building_id = '{$building_id}')
  AND (classroom_id = '${row['classroom_id']}')";
  $result2 = mysql_query($search2);


while($row = mysql_fetch_array($result2))
{}

显示mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\search_free2.php
use2里面存储了一些课室的使用信息,包括每节课使用的时间,课室号,哪一栋等等
然后现在实现的是输入栋号,时间查找空课室的功能,我先看按我输入的信息,看在这样的时间个栋号在use2里面有没有某些课室相关的信息,如果全部都没有相关的实现没有问题。
这是如果没有的实现,有点问题。我是想如果没有,就先把没有相关信息的课室找出来,再处理有相关信息的课室。但是找没有相关信息的课室,就显示如上错误,请指教!

------解决方案--------------------
$result1 = mysql_query($search1, $con) or die(mysql_error());
$result2 = mysql_query($search2) or die(mysql_error());

都提示什么错误。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn