1. <legend id='z23Uz'><style id='z23Uz'><dir id='z23Uz'><q id='z23Uz'></q></dir></style></legend>
  2. <tfoot id='z23Uz'></tfoot>
    • <bdo id='z23Uz'></bdo><ul id='z23Uz'></ul>

  3. <small id='z23Uz'></small><noframes id='z23Uz'>

      <i id='z23Uz'><tr id='z23Uz'><dt id='z23Uz'><q id='z23Uz'><span id='z23Uz'><b id='z23Uz'><form id='z23Uz'><ins id='z23Uz'></ins><ul id='z23Uz'></ul><sub id='z23Uz'></sub></form><legend id='z23Uz'></legend><bdo id='z23Uz'><pre id='z23Uz'><center id='z23Uz'></center></pre></bdo></b><th id='z23Uz'></th></span></q></dt></tr></i><div id='z23Uz'><tfoot id='z23Uz'></tfoot><dl id='z23Uz'><fieldset id='z23Uz'></fieldset></dl></div>

      mysqli fetch 数组只显示第一行

      时间:2023-09-24
        <tbody id='DU9sf'></tbody>
          <i id='DU9sf'><tr id='DU9sf'><dt id='DU9sf'><q id='DU9sf'><span id='DU9sf'><b id='DU9sf'><form id='DU9sf'><ins id='DU9sf'></ins><ul id='DU9sf'></ul><sub id='DU9sf'></sub></form><legend id='DU9sf'></legend><bdo id='DU9sf'><pre id='DU9sf'><center id='DU9sf'></center></pre></bdo></b><th id='DU9sf'></th></span></q></dt></tr></i><div id='DU9sf'><tfoot id='DU9sf'></tfoot><dl id='DU9sf'><fieldset id='DU9sf'></fieldset></dl></div>

            <legend id='DU9sf'><style id='DU9sf'><dir id='DU9sf'><q id='DU9sf'></q></dir></style></legend>
            • <bdo id='DU9sf'></bdo><ul id='DU9sf'></ul>
              1. <tfoot id='DU9sf'></tfoot>

              2. <small id='DU9sf'></small><noframes id='DU9sf'>

                本文介绍了mysqli fetch 数组只显示第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述


                我写了这段代码:


                I have written this code:

                require("config.php");
                
                $rows = array();
                
                $query = "SELECT accountname, bill_city, bill_code, bill_country,  bill_street, latitude, longitude, setype FROM vtiger_accountbillads, vtiger_account, vtiger_geocoding WHERE accountaddressid = accountid AND accountid = crmid";
                
                $result = mysqli_query($connection, $query);
                
                $rows_number = $result->num_rows;
                echo $rows_number . "<br/><br/>";
                
                $row = mysqli_fetch_array($result);
                
                if($result->num_rows > 0){
                    for($i=0; $i < $rows_number; $i++) {
                            $rows[] = array("name" => $row[0],
                                        "city" => $row[1],
                                        "code" => $row[2],
                                        "country" => $row[3],
                                        "street" => $row[4],
                                        "latitude" => $row[5],
                                        "longitude" => $row[6],
                                        "type" => $row[7]);
                    }
                }
                
                $json = json_encode($rows);
                print $json;
                
                mysqli_free_result($row);
                mysqli_close($connection);
                

                我正在尝试使用上面代码中编写的查询来获取多个数据,但它显示了第一行 47 次.为什么?我究竟做错了什么?谢谢!

                I'm trying to fetch several data using the query written in the code above, but it displays the first row 47 times. Why? What am I doing wrong? Thanks!

                推荐答案

                需要遍历 MySQL 返回的结果集.这意味着为该结果集的每一行调用 mysqli_fetch_array().你可以使用 while 循环来做到这一点:

                You need to iterate through the result set returned by MySQL. That means calling mysqli_fetch_array() for each row of that result set. You can do that using a while loop:

                while($row = mysqli_fetch_assoc($result)) {
                    $rows[] = array("name"      => $row['name'],
                                    "city"      => $row['bill_city'],
                                    "code"      => $row['bill_code'],
                                    "country"   => $row['bill_country'],
                                    "street"    => $row['bill_street'],
                                    "latitude"  => $row['latitude'],
                                    "longitude" => $row['longitude'],
                                    "type"      => $row['setype']);
                    }
                }
                

                这篇关于mysqli fetch 数组只显示第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli_real_escape_string() 需要 2 个参数,1 个给定致 下一篇:休假申请月报

                相关文章

                最新文章

              3. <legend id='LZ40k'><style id='LZ40k'><dir id='LZ40k'><q id='LZ40k'></q></dir></style></legend>

              4. <tfoot id='LZ40k'></tfoot>
                    <bdo id='LZ40k'></bdo><ul id='LZ40k'></ul>

                    <i id='LZ40k'><tr id='LZ40k'><dt id='LZ40k'><q id='LZ40k'><span id='LZ40k'><b id='LZ40k'><form id='LZ40k'><ins id='LZ40k'></ins><ul id='LZ40k'></ul><sub id='LZ40k'></sub></form><legend id='LZ40k'></legend><bdo id='LZ40k'><pre id='LZ40k'><center id='LZ40k'></center></pre></bdo></b><th id='LZ40k'></th></span></q></dt></tr></i><div id='LZ40k'><tfoot id='LZ40k'></tfoot><dl id='LZ40k'><fieldset id='LZ40k'></fieldset></dl></div>

                    <small id='LZ40k'></small><noframes id='LZ40k'>