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

        <bdo id='WGezH'></bdo><ul id='WGezH'></ul>

        <legend id='WGezH'><style id='WGezH'><dir id='WGezH'><q id='WGezH'></q></dir></style></legend>
      1. 虽然循环 PHP get_result 不起作用

        时间:2023-09-20
          <legend id='kdxBk'><style id='kdxBk'><dir id='kdxBk'><q id='kdxBk'></q></dir></style></legend>

        • <small id='kdxBk'></small><noframes id='kdxBk'>

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

                  本文介绍了虽然循环 PHP get_result 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 MySQl 准备好的语句从数据库中获取行并获得结果.然而,这是行不通的.

                  请有人知道我哪里出错了吗?我已经尝试了几个小时的解决方案,但我无法让它发挥作用.该页面不会加载,就好像查询失败一样.

                   $tag = trim($_GET['tag']);$stmt = $mysqli->prepare('SELECT posts.* FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');$stmt->bind_param('s', $tag);$stmt->execute();$stmt->store_result();$result = $stmt->get_result();while ($row = $result->fetch_assoc()) {回声 $row['tag'];}$stmt->free_result();$stmt->close();

                  解决方案

                  试试这个:

                  $stmt = $mysqli->prepare('SELECT posts.id FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');...$stmt->bind_result($id);而 ($stmt-> fetch()) {//var_dump 整行以确保您期望的密钥可用var_dump($id);}

                  更新

                  如果你想做一个选择 *,而不是单独指定每一列,看看这个 post(不是接受的答案,而是得分最高的答案).否则,我强烈建议您查看 PDO,因为它使这些基本的读取操作变得更加容易.>

                  I am trying to get rows from the database using MySQl prepared statements and get result. However this is not working.

                  Please can someone see where I am going wrong? I have been trying solutions for hours but I can't get it to work. The page just doesn't load as if the query has failed.

                   $tag = trim($_GET['tag']);
                  
                   $stmt = $mysqli->prepare('SELECT posts.* FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');
                   $stmt->bind_param('s', $tag);
                   $stmt->execute();
                   $stmt->store_result();
                   $result = $stmt->get_result();
                  
                   while ($row = $result->fetch_assoc()) {
                  
                       echo $row['tag'];
                  
                   }      
                  
                   $stmt->free_result();
                   $stmt->close();
                  

                  解决方案

                  Try this:

                  $stmt = $mysqli->prepare('SELECT posts.id FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');
                  
                  ...
                  
                  $stmt->bind_result($id);    
                  
                  while ($stmt->fetch()) {
                  
                      // var_dump entire row to ensure the key you expect is avail
                      var_dump($id);
                  
                  }
                  

                  Upate

                  If you want to do a select *, vs having to specify EVERY column individually, check out this post (not the accepted answer, but the highest scoring answer). Otherwise I strongly urge you to check out PDO, as it makes these basic read ops much easier.

                  这篇关于虽然循环 PHP get_result 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:对来自 while 循环的记录进行分组 |PHP 下一篇:在 MySQL 服务器上使用 PHP 进行循环

                  相关文章

                  最新文章

                    <bdo id='z79Lc'></bdo><ul id='z79Lc'></ul>

                  <tfoot id='z79Lc'></tfoot>

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

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