似乎無法找到解決此特定問題的帖子。 SQL查詢(如下所示)在我從shell執行時正常工作,但在PHP中拋出一個未定義的索引。我認爲問題在於它不能識別在php中時屬性的歧義。爲什麼這個JOIN查詢在shell中而不是在php中工作?
錯誤我在PHP中得到的是:
Notice: Undefined index: s.RowNumber in /home/xx/xx/xxx/xxx/checkAvailability.php on line 14.
代碼:
<?php
include'connect.php'
?>
<form method="post" action="chooseDate.php">
<?php
$sql = "SELECT s.RowNumber
FROM Seat AS s LEFT JOIN Booking AS b
ON s.RowNumber = b.RowNumber
AND b.PerfDate = '2016-12-12'
AND b.PerfTime = '20:30:00'
WHERE b.RowNumber IS NULL";
$handle = $conn->prepare($sql);
$handle->execute();
$res = $handle->fetchAll();
foreach($res as $row) {
echo "<input name='Seat' type='checkbox' value=".$row['s.RowNumber']."><br>";
}
?>
<input class="mybutton" type="submit" value="Choose Date"/>
</form>
任何人都可以對這個問題解釋一下?提前致謝。
如果你_「未定義指數」 _,它不是SQL查詢這是個問題。閱讀更多關於它在這裏:http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index –