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

      <legend id='TD2Ye'><style id='TD2Ye'><dir id='TD2Ye'><q id='TD2Ye'></q></dir></style></legend>

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

        在 mysqli 中存储和迭代查询结果

        时间:2023-07-29
          • <bdo id='XaUcj'></bdo><ul id='XaUcj'></ul>
          • <i id='XaUcj'><tr id='XaUcj'><dt id='XaUcj'><q id='XaUcj'><span id='XaUcj'><b id='XaUcj'><form id='XaUcj'><ins id='XaUcj'></ins><ul id='XaUcj'></ul><sub id='XaUcj'></sub></form><legend id='XaUcj'></legend><bdo id='XaUcj'><pre id='XaUcj'><center id='XaUcj'></center></pre></bdo></b><th id='XaUcj'></th></span></q></dt></tr></i><div id='XaUcj'><tfoot id='XaUcj'></tfoot><dl id='XaUcj'><fieldset id='XaUcj'></fieldset></dl></div>
              <tbody id='XaUcj'></tbody>
            <tfoot id='XaUcj'></tfoot>
          • <small id='XaUcj'></small><noframes id='XaUcj'>

                  <legend id='XaUcj'><style id='XaUcj'><dir id='XaUcj'><q id='XaUcj'></q></dir></style></legend>
                1. 本文介绍了在 mysqli 中存储和迭代查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是我在 php 中的简单查询,使用 mysqli 面向对象的风格:

                  This is my simple query in php, using mysqli object oriented style:

                  $query = "SELECT name FROM usertable WHERE id = ?";
                  $stmt = $mysqli->prepare($query);
                  $stmt->bind_param('i', $id);
                  $id= $_GET['id'];
                  $stmt->execute();
                  $stmt->bind_result($name);
                  
                  while($stmt->fetch()){
                     echo $name." ";
                  }
                  
                  $stmt->free_result();
                  $stmt->close();
                  

                  这很好用.我获得了从 select 语句中检索到的名称列表.

                  This works fine. I obtain the list of name retrieved from the select statement.

                  现在,在 while 我想使用 $name 变量作为另一个查询的参数,但 mysqli 不允许这样做,因为我必须关闭第一个查询,然后调用第二个查询.

                  Now, inside the while I want use the $name variable as parameter for another query, but mysqli do not allow this, since I have to close the first query and then call the second query.

                  所以我想我必须存储第一个查询的结果,然后调用新查询来迭代结果.

                  So I think I have to store the result of the first query and then iterate over the result calling a new query.

                  我尝试了以下方法:

                  $query = "SELECT name FROM usertable WHERE id = ?";
                  $stmt = $mysqli->prepare($query);
                  $stmt->bind_param('i', $id);
                  $id= $_GET['id'];
                  $stmt->execute();
                  //$stmt->bind_result($name);
                  $result = $stmt->store_result();
                  $stmt->free_result();
                  $stmt->close();
                  
                  while ($row = $result->fetch_row()) 
                  {
                      echo $row[0]." ";
                  }
                  

                  但这行不通.while 中的代码永远无法访问.

                  But this does not work. The code inside while is never reached.

                  注意:我想避免使用 multi_query().

                  推荐答案

                  我已经解决了问题:

                  $query = "SELECT name FROM usertable WHERE id = ?";
                  $stmt = $mysqli->prepare($query);
                  $stmt->bind_param('i', $id);
                  $id= $_GET['id'];
                  $stmt->execute();
                  $result = $stmt->get_result();
                  $stmt->free_result();
                  $stmt->close();
                  
                  while ($row = $result->fetch_array(MYSQLI_NUM)) 
                  {
                      echo $row[0]." ";
                  }
                  

                  只需使用 get_result()fetch_array()

                  这篇关于在 mysqli 中存储和迭代查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何让 mysqli 在 SQL 语句中使用分隔符? 下一篇:使用准备好的语句编写查询的分页结果集,

                  相关文章

                  最新文章

                  <legend id='11oVQ'><style id='11oVQ'><dir id='11oVQ'><q id='11oVQ'></q></dir></style></legend>

                  1. <tfoot id='11oVQ'></tfoot>

                    <small id='11oVQ'></small><noframes id='11oVQ'>

                      <bdo id='11oVQ'></bdo><ul id='11oVQ'></ul>

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