dongxi8993 2015-09-08 18:57
浏览 58
已采纳

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

i m trying to get a json for my android application but i m getting an error: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in /home/a5872453/public_html/GetAllGreenhouse.php on line 17

this is my code:

  <?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);


?>
  • 写回答

1条回答 默认 最新

  • dopr25398 2015-09-08 20:30
    关注

    OK...Thanks i solved it. here is the correct code:

    <?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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 定制ai直播实时换脸软件
  • ¥100 栈回溯相关,模块加载后KiExceptionDispatch无法正常回溯了
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台