[英]Inner Join Query PHP issue MySQL
I have two tables 1) live_booking table 2) company_car table 我有两个表1)live_booking表2)company_car表
the company car PK is car_id
. 公司的汽车PK是
car_id
。 there is a field in the booking table with the car_id for a user to input. 预订表中有一个带有car_id的字段供用户输入。
The issue is that when the user runs the SQL query it doesnt return any results, if there is no car_id in the booking table, However if the car_id present into the booking table by the user then the SQL query shows all the results. 问题是,当用户运行SQL查询时,如果预订表中没有car_id,则不会返回任何结果;但是,如果用户在预订表中存在car_id,则SQL查询将显示所有结果。
I would like it that if there is NO car_id in the booking table then the query gets the remaining fields from the booking table and shows the car fields as blank. 我希望如果预订表中没有car_id,那么查询将从预订表中获取剩余字段,并将汽车字段显示为空白。
$bookingid = $_GET['id'];
$result = mysqli_query($con, "
SELECT
live_booking.booking_id, live_booking.booking_time, live_booking.booking_date, live_booking.id_mobile,live_booking.reservation_time, live_booking.car_id,
company_cars.car_driver, company_cars.car_make, company_cars.car_model,
customer.eu_name
FROM live_booking live_booking
inner join customer customer on customer.id_mobile = live_booking.id_mobile
inner join company_cars company_cars on company_cars.car_id = live_booking.car_id
WHERE booking_id = $bookingid");
you can use mysqli_num_rows and if statement here if No result then show rest of all results 您可以使用mysqli_num_rows并在此处使用if语句,如果没有结果,则显示所有结果的其余部分
like 喜欢
$row_cnt = $result->num_rows;
if ($row_cnt == 0)
{
do this
}
else
{
do this
}
for more information check this http://www.php.net/manual/en/mysqli-result.num-rows.php 有关更多信息,请检查此http://www.php.net/manual/en/mysqli-result.num-rows.php
plus choice right tags :) 加上选择权标签:)
I only needed to use a Left Join instead of inner join. 我只需要使用左联接而不是内部联接。 http://www.w3schools.com/sql/sql_join_left.asp
http://www.w3schools.com/sql/sql_join_left.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.