久久久久久久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` 查詢跳過返回的第一個結(jié)果

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

          <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` 查詢跳過返回的第一個結(jié)果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在過渡到 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 語句回顯了正確的結(jié)果,但是 PDO::FETCH_ASSOC 查詢跳過了返回的第一個結(jié)果(因此它總是回顯小于它的一個結(jié)果應(yīng)該).

                  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 />";  
                  }
                  

                  推薦答案

                  您已經(jīng)在 while 循環(huán)之前獲取了第一行 $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 循環(huán)會在每次迭代時覆蓋 $row,看起來您是從第二行開始的,但實際發(fā)生的是 $row 的值在首先覆蓋 while 循環(huán)迭代.

                  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.

                  要讓循環(huán)按照您編寫的方式工作,您需要使用 do-while 構(gòu)造:

                  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.

                  在這種特殊情況下,當沒有任何結(jié)果時,我不想回顯任何內(nèi)容

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

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

                  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 />"; 
                     }
                  }
                  

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

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

                  相關(guān)文檔推薦

                  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 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

                  <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>
                          • 主站蜘蛛池模板: 欧美亚洲国产一区 | 亚洲精品一区二区三区中文字幕 | 91网在线观看 | 国产欧美精品一区二区 | 欧美 日韩 综合 | 看片地址| 亚洲夜夜爽 | 91人人视频在线观看 | 亚洲av毛片 | 中文字幕亚洲区一区二 | 日韩中文字幕视频 | 亚洲午夜在线 | 欧美一区二区三区视频在线 | 国产午夜精品视频 | 欧美一二三四成人免费视频 | 国产成人a亚洲精品 | 精品视频一区二区三区在线观看 | 国产精品久久久久久久久久免费看 | www.狠狠操| 国产精品综合色区在线观看 | 亚洲最大av网站 | 免费三级黄| 国产91精品久久久久久久网曝门 | 欧美激情视频一区二区三区在线播放 | 日韩高清中文字幕 | 天天看天天干 | 天天插天天操 | 日本二区 | 精品一区二区久久久久久久网站 | 国产成人精品免高潮在线观看 | 久久精品一区二区 | 国产精品久久一区 | 国产一区欧美 | 国产精品久久久久久久免费观看 | 国产一区二区三区精品久久久 | 成年网站在线观看 | 国产精品91久久久久久 | 国产欧美精品一区二区三区 | 亚洲精品日本 | 欧美日一区 | 久久精品国产a三级三级三级 |