久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

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

        此 PDO::FETCH_ASSOC` 查詢跳過返回的第一個結果

        This PDO::FETCH_ASSOC` query skips the 1rst result that#39;s returned(此 PDO::FETCH_ASSOC` 查詢跳過返回的第一個結果)

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

          <tfoot id='EpRxq'></tfoot>
                <bdo id='EpRxq'></bdo><ul id='EpRxq'></ul>
                <legend id='EpRxq'><style id='EpRxq'><dir id='EpRxq'><q id='EpRxq'></q></dir></style></legend>
                  <tbody id='EpRxq'></tbody>

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

                  本文介紹了此 PDO::FETCH_ASSOC` 查詢跳過返回的第一個結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在過渡到 PDO 準備好的語句,但我在使用 WHILE 語句的基本 SELECT 查詢的語法方面遇到了問題.

                  I'm transitioning over to PDO prepared statements, and I'm having trouble with the syntax for a basic SELECT query with a WHILE statement.

                  下面的 foreach 語句回顯了正確的結果,但是 PDO::FETCH_ASSOC 查詢跳過了返回的第一個結果(因此它總是回顯小于它的一個結果應該).

                  The foreach statement below echos the correct results, but the PDO::FETCH_ASSOC query is skipping the 1rst result that's returned (so it always echo's one result less than it should).

                  PDO::FETCH_ASSOC

                  $stmt = $conn->prepare("SELECT * FROM products"); 
                  $stmt->execute();
                  $row = $stmt->fetch();
                  while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
                      echo $row['product_name'].' '.$row['price'].' '.$row['color'], "<br />"; 
                  }
                  

                  foreach

                  foreach($conn->query('SELECT * FROM products') as $row) {
                      echo $row['product_name'].' '.$row['price'].' '.$row['color'], "<br />";  
                  }
                  

                  推薦答案

                  您已經在 while 循環之前獲取了第一行 $row = $stmt->fetch();.如果您刪除此行,它將按預期工作.

                  You already fetched the first row before the while loop $row = $stmt->fetch();. If you remove this line, it will work as expected.

                  由于 while 循環會在每次迭代時覆蓋 $row,看起來您是從第二行開始的,但實際發生的是 $row 的值在首先覆蓋 while 循環迭代.

                  Since the while loop will overwrite $row on each iteration, it looks like you start with the second row, but what happens is the value of $row at the first while loop iteration is overwritten.

                  要讓循環按照您編寫的方式工作,您需要使用 do-while 構造:

                  To have the loop work the way you have written, you would need to use a do-while construct:

                  $row = $stmt->fetch();
                  do {
                       echo $row['product_name'].' '.$row['price'].' '.$row['color'], "<br />";
                  } while($row = $stmt->fetch(PDO::FETCH_ASSOC));
                  

                  這里首先打印$row的值,然后被while條件覆蓋.

                  Here the value of $row will be printed first, before it is overwritten by the while condition.

                  在這種特殊情況下,當沒有任何結果時,我不想回顯任何內容

                  In this particular case I don't want to echo anything when there aren't any results

                  如果是這種情況,請先檢查您的查詢是否返回了任何結果.在這里,我在檢查中是明確的,因為如果您刪除外部 if,您的 while 循環仍會遵循您的意圖 - 也就是說,它不會回顯任何內容如果沒有任何結果.

                  If that's the case, then check to see if your query returned any results first. Here I'm being explicit in the check, because if you removed the outer if, your while loop would still follow your intentions - that is, it won't echo anything if there aren't any results.

                  但是,在您的代碼中有明確的意圖總是好的:

                  However, it is always good to have clear intent in your code:

                  if ($stmt->columnCount()) {
                     while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
                         echo $row['product_name'].' '.$row['price'].' '.$row['color'], "<br />"; 
                     }
                  }
                  

                  這篇關于此 PDO::FETCH_ASSOC` 查詢跳過返回的第一個結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

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

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

                    • <bdo id='HUUAm'></bdo><ul id='HUUAm'></ul>
                    • <tfoot id='HUUAm'></tfoot>

                        <tbody id='HUUAm'></tbody>

                      1. <legend id='HUUAm'><style id='HUUAm'><dir id='HUUAm'><q id='HUUAm'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 亚洲啊v在线 | 国产精品乱码一区二三区小蝌蚪 | 久草成人| 久久三区 | 色婷婷久久久亚洲一区二区三区 | 成人在线播放网址 | 欧美一区二区三区在线 | 国产成人精品一区二区三区在线观看 | 日韩中文字幕免费 | 黄色一级大片在线免费看产 | 在线播放亚洲 | 精品一级 | 亚洲 中文 欧美 | 亚洲国产成人精品久久 | hsck成人网| 欧美日韩视频一区二区 | 久草视| 日韩在线视频一区 | 国产午夜视频 | 蜜桃视频麻豆 | 91精品在线播放 | 国产一区二区在线播放 | 黄网在线观看 | 婷婷五月色综合香五月 | 91视频免费观看 | 亚洲码欧美码一区二区三区 | 亚洲一区二区三区国产 | 99精品国产一区二区三区 | 午夜伦4480yy私人影院 | 免费毛片www com cn | 亚洲人成人一区二区在线观看 | 在线观看av不卡 | 国产综合久久 | 精品麻豆剧传媒av国产九九九 | 四虎午夜剧场 | 91精品国产乱码久久久久久久 | 午夜寂寞福利视频 | 日韩区| 一级黄色片美国 | 在线观看国产www | 一区二区视屏 |