Php MySQL查询,用于返回数据库中按用户输入过滤的两个表中的信息
我正在做的项目是一个公交车预订应用程序,我目前正忙于我的“Search.php”文件,该文件将查询在线mysql服务器上的行程日期、位置、目的地、行程计划时间和价格。将从“行程”表中检索用户指定的日期,并从另一个“公交路线”表中获取有关用户位置、其目的地、当天出行的各种时间安排以及价格的信息 目前,我已尝试使用左连接连接两个表,如下所示,但不知道是否有用。如有任何建议和更正,将不胜感激 Search.phpPhp MySQL查询,用于返回数据库中按用户输入过滤的两个表中的信息,php,mysql,Php,Mysql,我正在做的项目是一个公交车预订应用程序,我目前正忙于我的“Search.php”文件,该文件将查询在线mysql服务器上的行程日期、位置、目的地、行程计划时间和价格。将从“行程”表中检索用户指定的日期,并从另一个“公交路线”表中获取有关用户位置、其目的地、当天出行的各种时间安排以及价格的信息 目前,我已尝试使用左连接连接两个表,如下所示,但不知道是否有用。如有任何建议和更正,将不胜感激 Search.php <?php $con = mysqli_connect("local
<?php
$con = mysqli_connect("localhost", "id625053_admin", "12345", "id625053_bookbus");
$from = $_POST["location"];
$to = $_POST["destination"];
$tdate = $_POST["travelDate"];
$statement = mysqli_prepare($con, "
SELECT t.trip_date
, b.route_from
, b.route_to
, b.time
, b.price
FROM trip t
LEFT
JOIN bus_route b
ON t.route_id = b.route_id
WHERE route_from = ?
AND route_to = ?
AND trip_date = ?
");
mysqli_stmt_bind_param($statement, "ss", $from, $to, $tdate);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $trip_date, $route_from, $route_to, $time, $price);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["trip_date"] = $trip_date;
$response["route_from"] = $route_from;
$response["route_to"] = $route_to;
$response["time"] = $time;
$response["price"] = $price;
}
echo json_encode($response);
?>
我怀疑您在查询表时,日期的格式可能有问题。您需要确保使用相同的日期格式进行查询(默认为“YYYY-MM-DD”)。请尝试替换
mysqli\u stmt\u bind\u参数($statement,“ss”,$from,$to,$tdate)
到这个mysqli\u stmt\u bind\u param($statement,“sss”,$from,$to,$tdate)
@M.Rizzo我通过输入诸如$from=“London”、$to=“Manchester”、$tdate=“2017-02-05”之类的硬编码值对其进行了测试……但我仍然收到错误“警告:mysqli_stmt_bind_param()期望参数1为mysqli_stmt”@ntaloventi尝试过……没有运气……相同的错误”警告:mysqli_stmt_bind_param()预期参数1是mysqli_stmt,第10行的/storage/h2/053/625053/public_html/Search1.php中给出的布尔值“$stament变为布尔值,是您的连接没有抛出错误吗?我怀疑您在查询表时,日期的格式可能有问题。您需要确保使用相同的日期格式进行查询(默认为“YYYY-MM-DD”)。请尝试替换mysqli\u stmt\u bind\u参数($statement,“ss”,$from,$to,$tdate)
到这个mysqli\u stmt\u bind\u param($statement,“sss”,$from,$to,$tdate)
@M.Rizzo我通过输入诸如$from=“London”、$to=“Manchester”、$tdate=“2017-02-05”之类的硬编码值对其进行了测试……但我仍然收到错误“警告:mysqli_stmt_bind_param()期望参数1为mysqli_stmt”@ntaloventi尝试过……没有运气……相同的错误”警告:mysqli_stmt_bind_param()预期参数1为mysqli_stmt,布尔值在第10行的/storage/h2/053/625053/public_html/Search1.php中给出“$stament变为布尔值,您的连接没有抛出错误吗?