【发布时间】:2018-10-07 14:34:31
【问题描述】:
<?php
$mysqli = new mysqli("localhost", "root", "", "titan3d");
if (mysqli_connect_error()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sdate = "";
$stime = "";
if(isset($_POST['sdate']))
{
$sdate = $_POST["sdate"];
}
if(isset($_POST['stime']))
{
$stime = $_POST["stime"];
}
$statement = $mysqli->prepare("SELECT bookedseat FROM bookings WHERE sdate = ? AND stime = ?");{
$statement->bind_param("si", $sdate, $stime);
if (!$statement->execute()) {
trigger_error('Error executing MySQL query: ' . $statement->error);
}
$statement->bind_result($book);
$statement->fetch();
printf($book);
//header('Location: http://localhost/My%20Project/seats.html');
$statement->close();
}
$mysqli->close();
?>
这是我的 php 文件,用于从表单中获取数据并进行查询,然后显示结果。
执行后,php完美运行。
但它只显示查询中的第一个值。
为什么会这样?
如何显示查询中的所有值?
【问题讨论】:
-
遍历结果集或者只使用 fetch all for mysqli
-
PHP 代码不是可运行的 sn-p。当您发布您的 php 代码块时,突出显示文本,然后按
Ctrl + K将其格式化为代码块。请在您的代码中使用面向对象或过程化的mysqli_函数(不能同时使用两者)。