gpt4 book ai didi

php - while 循环将所有行连接为一行?

转载 作者:行者123 更新时间:2023-11-29 11:24:21 25 4
gpt4 key购买 nike

我正在尝试使用外键从表中获取所有行。我的 while 循环仅返回一行,其中包含来自应该返回的两行的分散数据。

$ins = 'SELECT * FROM car_reg INNER JOIN User_Details ON car_reg.User_ID = User_Details.User_ID WHERE car_regColumn = userinput AND car_regColumn = userinput';
$qur = $con->query($ins);
if(mysqli_num_rows($qur) > 0){
while{$g = mysqli_fetch_array($qur)
$response = array("status" => 1 "Surname" => $g['fname'], $"Surname" => $g["fname"], "LastName" => $g["lname"], "CarType" => $g["Car_Type"], "NumberPlate" => $g["Number_plate"], "CarImage" => $g["car_image"], "Gender" => $g["Gender"], "Mobile" => $g["Telephone"], "Price" => $g["Price"], "PickupTime" => $g["arrival_time"]);}}

json_encode($response);

最佳答案

您的$response已在while循环中被覆盖。声明一个数组并将获取的数据插入其中。试试这个代码:

$response = array();
$ins = 'SELECT * FROM car_reg INNER JOIN User_Details ON car_reg.User_ID = User_Details.User_ID WHERE car_regColumn = userinput AND car_regColumn = userinput';
$qur = $con->query($ins);
if(mysqli_num_rows($qur) > 0){
while($g = mysqli_fetch_array($qur))
{
$response[] = array("status" => 1, "Surname" => $g['fname'], "Surname" => $g["fname"], "LastName" => $g["lname"], "CarType" => $g["Car_Type"], "NumberPlate" => $g["Number_plate"], "CarImage" => $g["car_image"], "Gender" => $g["Gender"], "Mobile" => $g["Telephone"], "Price" => $g["Price"], "PickupTime" => $g["arrival_time"]);
}

关于php - while 循环将所有行连接为一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38483257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com