我有两个MySQL表:
table officehours(ID,dayslot,appt_time) table appt(ID,appt_date,appt_time)
我想选择当时没有预约的特定日期(例如2016-01-26)的所有办公时间。 (可用时间)
在我的查询代码中,我有:
// get BOOKED appointment times
mysql_select_db($database_IHC, $IHC);
$query_booked18 = "SELECT appt_time FROM appt WHERE appt_date =
'".$monthyear."-".$monthnum."-18'";
$booked18 = mysql_query($query_booked18, $IHC);
// MAKE BOOKED QUERY PART OF NOT IN STATEMENT FOR AVAILABLE QUERY
while($row = mysql_fetch_array($booked18)){
$temp[] = '"'.$row[0].'"';
// PUT COMMAS BETWEEN VALUES
$bookedstmt18 = implode(",",$temp);
// AVAILABLE APPOINTMENTS QUERY
$query_available18 = "SELECT * FROM officehours WHERE dayslot =
(dayofweek('".$monthyear."-".$monthnum."-18')-1) AND appt_time NOT IN
(".$bookedstmt18.") ORDER BY (date) desc";
$available18 = mysql_query($query_available18, $IHC);
$row_available18 = mysql_fetch_assoc($available18);
$totalRows_available18 = mysql_num_rows($available18);
在显示约会(18.php)的日历部分,我有:
//check to see if closed first
if ($totalRows_closed18 > 0 ) {
echo "<td>CLOSED: </td><td>".$row_closed18['reason']."</td>";
echo $query_available18;
} else { // SHOW AVAILABLE APPOINTMENTS
echo '<td width="92" height="75" align="left" valign="top" style="text- align: left">';
do {
<a href="https://innerhealerchiropractic.com/index.php/appt/VIPschedule/" class="w3-link"><?php echo $row_available18['appt_time']; ?></a></br>
<?php } while ($row_available18 = mysql_fetch_assoc($available18));
echo '</td><td width="92" align="left" valign="top" style="text- align:left"> </td>';
} // END SHOW APPOINTMENTS ?>
我收到错误 -
&#34;错误500 mysql_fetch_assoc()期望参数1是资源, 布尔给出&#34;
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
您的错误是由于您的SQL查询中包含错误
基本上,您正在执行的操作与执行子查询的操作相同,因为您获得的是单个结果和内爆。因此,让我们将其分解为易于理解的代码行:
$totalquery = "
SELECT * FROM officehours
WHERE
dayslot = (
dayofweek('".$monthyear."-".$monthnum."-18')-1
) AND
appt_time NOT IN (
SELECT appt_time FROM appt
WHERE appt_date = '".$monthyear."-".$monthnum."-18'
)
ORDER BY date desc";
不在的子查询与另一个选择的行为方式相同,然后对值进行内爆。
然后我们只查询并获取assoc
$totalresults = mysql_fetch_assoc($totalquery);
$totalrows = mysql_num_rows($totalquery);
这应该替换您的整个第一部分代码并解决您的错误。