gpt4 book ai didi

从服务器检索多行时出现php错误

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

我正在尝试为我的 Android 应用程序获取 json,但出现错误:mysqli_fetch_array() 期望参数 1 为 mysqli_result,该对象在 /home/a5872453/public_html/GetAllGreenhouse.php17 行

中给出

这是我的代码:

  <?php

$con=mysqli_connect("mysql3.000webhost.com","xxx","xxx","xxx");

$farmname = $_POST["farmname"];


$statement = mysqli_prepare($con, "SELECT * FROM GreenHouse WHERE farm_name = ?");
mysqli_stmt_bind_param($statement, "s", $farmname);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $ghid, $name, $farmname, $planttype, $linefrom, $lineto, $barcode);



$response["greenhouses"] = array();

while($row = mysqli_fetch_array($statement)){
$greenhouse= array();
$greenhouse["ghid"]=$row[$ghid];
$greenhouse["name"]=$row[$name];
$greenhouse["farmname"]=$row[$farmname];
$greenhouse["planttype"]=$row[$planttype];
$greenhouse["linefrom"]=$row[$linefrom];
$greenhouse["lineto"]=$row[$lineto];
$greenhouse["barcode"]=$row[$barcode];

// push single product into final response array
array_push($response["greenhouses"], $greenhouse);
}


echo json_encode($response);
mysqli_stmt_close($statement);
mysqli_close($con);


?>

最佳答案

好的...谢谢我解决了。这是正确的代码:

<?php

$con=mysqli_connect("mysql3.000webhost.com","xxx","xxx","xxx");
$farmname = $_POST["farmname"];


$statement = mysqli_prepare($con, "SELECT * FROM GreenHouse WHERE farm_name= ?");
mysqli_stmt_bind_param($statement, "s", $farmname);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $ghid, $name, $farmname, $planttype, $linefrom, $lineto,$barcode);

$greenhouses["greenhouses"] = array();

while(mysqli_stmt_fetch($statement)){
$greenhouse= array();
$greenhouse["ghid"]=$ghid;
$greenhouse["name"]=$name;
$greenhouse["farmname"]=$farmname;
$greenhouse["planttype"]=$planttype;
$greenhouse["linefrom"]=$linefrom;
$greenhouse["lineto"]=$lineto;
$greenhouse["barcode"]=$barcode;
array_push($greenhouses["greenhouses"], $greenhouse);

}

echo json_encode($greenhouses);
mysqli_stmt_close($statement);
mysqli_close($con);

关于从服务器检索多行时出现php错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32465282/

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