undefindex索引,mysqli_query,没有结果吐回来

时间:2013-12-26 04:30:10

标签: php mysqli

我正在按照教程来构建日历。最初,它是用mysql构建的,我把它重写了一点,以便mysqli遵循php推荐。

我陷入了最后一步,我正试图从数据库中获取事件/日的描述。我没有/ emtpy结果。

我的日历表格如下:[id] [evdate] [description]

这是我的代码,我在第13行得到通知未指定的索引 - 非常感谢您的帮助

$deets = $_POST['deets'];
$deets = preg_replace('#[^0-9/]#i', '', $deets);

include_once('inc/connection.inc.php');
$events = '';
$sql = "SELECT id FROM events WHERE evdate = '$deets'";
$query = mysqli_query($connection, $sql);
$num_rows = mysqli_num_rows ($query);
if($num_rows > 0){
    $events .= '<div id="eventControl"><button onmousedown="overlay()">Close</button><br><strong>'. $deets .'</strong></div>'; // Add a close Button
while($row = mysqli_fetch_assoc($query)) {
    $desc = $row['description']; // Notice undefindex Index :(
    $events .= '<div id="eventsbody">'. $desc .'</div>';
}
}
echo $events;

1 个答案:

答案 0 :(得分:1)

您只是选择id,但尝试检索description。将您的查询更新为:

$sql = "SELECT id, description FROM events WHERE evdate = '$deets'";