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

    1. <tfoot id='YcuEd'></tfoot>
      <legend id='YcuEd'><style id='YcuEd'><dir id='YcuEd'><q id='YcuEd'></q></dir></style></legend>

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

      1. 嵌套 while 循环只运行一次

        时间:2023-09-20

          <small id='3IcsC'></small><noframes id='3IcsC'>

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

            <legend id='3IcsC'><style id='3IcsC'><dir id='3IcsC'><q id='3IcsC'></q></dir></style></legend>

                • 本文介绍了嵌套 while 循环只运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  嵌套的while"循环只运行一次,只显示一个div,找不到任何错误,0个错误在error_log".欢迎提出建议.

                  我需要第二个 sql 连接,因为 $connectToStore 使 mysqli 连接到单独的数据库.

                  $items 看起来像 1-2,2-5,9-1

                  我已经检查过,显示的 div 使用了表格第一行中的数据

                  PHP

                  include("connect.php");$sql = "SELECT * FROM sp_tickets WHERE user_id='foo'";$sqlresult = mysqli_query($connect, $sql);如果 (mysqli_num_rows($sqlresult) > 0) {而 ($row = mysqli_fetch_array($sqlresult)) {$sqlStore = "SELECT * FROM transactions WHERE order_id='".$row['order_id']."'";$connectToStore = mysqli_connect("localhost", "root", "root", "root_db");$sqlStoreDBResult = mysqli_query($connectToStore, $sqlStore);而 ($rowTr = mysqli_fetch_array($sqlStoreDBResult)) {$id_str_array = $rowTr['items'];$id_str_array = rtrim($id_str_array, ",");$id_str_array =explode(',', $id_str_array);foreach ($id_str_array as $key => $value) {$id_quantity_pair = expand("-", $value);//使用连字符(-) 作为分隔符将产品 ID 与其数量分开$product_id = $id_quantity_pair[0];//获取产品ID$sqlProduct = "SELECT * FROM products WHERE id='$product_id'";$sqlresult = mysqli_query($connectToStore, $sqlProduct);而 ($pp_row = mysqli_fetch_array($sqlresult)) {$tickets .='

                  <div data-ticket="' . $ticket . '" class="ticket"><div class="ticket-left"><span class="product-ticket left-span">'.$pp_row['product_name'] .' ' .$pp_row['product_platform'] .' ' .$pp_row['product_type'] .' ' .$pp_row['product_region'] .'</span><span class="ticket-no left-span">票号' .$row['ticket_id'] .'</span><span class="order-no left-span">订单号' .$row['order_id'] .'</span><span class="left-span">交易号' .$rowTr['txn_id'] .'</span><span class="product-region left-span">区域:' .$pp_row['product_region'] .'</span>

                  <div class="ticket-right"><span class="created">Created: ' .$row['date'] .'</span>

                  <div class="ticket-bottom"><div class="bottom-holder"><span class="details"><span class="subject-txt">类别:</span>'.$row['category'] .'</span><span class="details"><span class="subject-txt">主题:</span>'.$row['subject'] .'</span><span class="details desc">"' . $row['description'] . '"</span>

                  <div class="removeticketcontainer"><span class="removeticket">X</span>

                  ';}}}}}

                  解决方案

                  解决了.答案属于 @ckimbrell.问题看起来像是您正在用仅返回 1 行的新结果覆盖变量 $sqlresult.尝试在嵌套循环中更改它."

                  include("connect.php");$sql = "SELECT * FROM sp_tickets WHERE user_id='foo'";$sqlresult = mysqli_query($connect, $sql);$connectToStore = mysqli_connect("localhost", "root", "root", "root_db");如果 (mysqli_num_rows($sqlresult) > 0) {而 ($row = mysqli_fetch_array($sqlresult)) {$sqlStore = "SELECT * FROM transactions WHERE order_id='".$row['order_id']."'";$sqlStoreDBResult = mysqli_query($connectToStore, $sqlStore);而 ($rowTr = mysqli_fetch_array($sqlStoreDBResult)) {$id_str_array = $rowTr['items'];$id_str_array = rtrim($id_str_array, ",");$id_str_array =explode(',', $id_str_array);foreach ($id_str_array as $key => $value) {$id_quantity_pair = expand("-", $value);//使用连字符(-) 作为分隔符将产品 ID 与其数量分开$product_id = $id_quantity_pair[0];//获取产品ID$sqlProduct = "SELECT * FROM products WHERE id='$product_id'";$sqlresult2 = mysqli_query($connectToStore, $sqlProduct);而 ($pp_row = mysqli_fetch_array($sqlresult2)) {$tickets .='

                  <div data-ticket="' . $ticket . '" class="ticket"><div class="ticket-left"><span class="product-ticket left-span">'.$pp_row['product_name'] .' ' .$pp_row['product_platform'] .' ' .$pp_row['product_type'] .' ' .$pp_row['product_region'] .'</span><span class="ticket-no left-span">票号' .$row['ticket_id'] .'</span><span class="order-no left-span">订单号' .$row['order_id'] .'</span><span class="left-span">交易号' .$rowTr['txn_id'] .'</span><span class="product-region left-span">区域:' .$pp_row['product_region'] .'</span>

                  <div class="ticket-right"><span class="created">Created: ' .$row['date'] .'</span>

                  <div class="ticket-bottom"><div class="bottom-holder"><span class="details"><span class="subject-txt">类别:</span>'.$row['category'] .'</span><span class="details"><span class="subject-txt">主题:</span>'.$row['subject'] .'</span><span class="details desc">"' . $row['description'] . '"</span>

                  <div class="removeticketcontainer"><span class="removeticket">X</span>

                  ';}}}}}

                  Nested "while" loop runs only one time, only one div is displayed, can't find any mistakes, 0 errors in "error_log". Feel free to suggest.

                  I need second sql connection, because $connectToStore makes mysqli connection with separate database.

                  $items looks like 1-2,2-5,9-1

                  I've checked and div that's displayed uses data which is in the first row of the table

                  PHP

                  include("connect.php");
                  
                  $sql = "SELECT * FROM sp_tickets WHERE user_id='foo'";
                  $sqlresult = mysqli_query($connect, $sql);
                  if (mysqli_num_rows($sqlresult) > 0) {
                      while ($row = mysqli_fetch_array($sqlresult)) {
                  
                      $sqlStore = "SELECT * FROM transactions WHERE order_id='".$row['order_id']."'";
                      $connectToStore = mysqli_connect("localhost", "root", "root", "root_db");
                      $sqlStoreDBResult = mysqli_query($connectToStore, $sqlStore);
                  
                      while ($rowTr = mysqli_fetch_array($sqlStoreDBResult)) {
                  
                          $id_str_array = $rowTr['items'];
                          $id_str_array = rtrim($id_str_array, ",");
                          $id_str_array = explode(',', $id_str_array);
                          foreach ($id_str_array as $key => $value) {
                              $id_quantity_pair = explode("-", $value); // Uses Hyphen(-) as delimiter to separate product ID from its quantity
                              $product_id = $id_quantity_pair[0]; // Get the product ID
                  
                              $sqlProduct = "SELECT * FROM products WHERE id='$product_id'";
                              $sqlresult = mysqli_query($connectToStore, $sqlProduct);
                              while ($pp_row = mysqli_fetch_array($sqlresult)) {
                  
                                  $tickets .= '<div class="holder">
                                  <div data-ticket="' . $ticket . '" class="ticket">
                                      <div class="ticket-left">
                                          <span class="product-ticket left-span">' . $pp_row['product_name'] . ' ' . $pp_row['product_platform'] . ' ' . $pp_row['product_type'] . ' ' . $pp_row['product_region'] . '</span>
                                          <span class="ticket-no left-span">Ticket No. ' . $row['ticket_id'] . '</span>
                                          <span class="order-no left-span">Order No. ' . $row['order_id'] . '</span>
                                          <span class="left-span">Transaction No. ' . $rowTr['txn_id'] . '</span>
                                          <span class="product-region left-span">Region: ' . $pp_row['product_region'] . '</span>
                                      </div>
                                      <div class="ticket-right">
                                          <span class="created">Created: ' . $row['date'] . '</span>
                                      </div>
                                      <div class="ticket-bottom">
                                          <div class="bottom-holder">
                                              <span class="details"><span class="subject-txt">Category: </span>' . $row['category'] . '</span>
                                              <span class="details"><span class="subject-txt">Subject: </span>' . $row['subject'] . '</span>
                                              <span class="details desc">"' . $row['description'] . '"</span>
                                          </div>
                                      </div>
                                  </div>
                                  <div class="removeticketcontainer">
                                      <span class="removeticket">X</span>
                                  </div>
                               </div>';
                                  }
                              }
                          }
                      }
                  }
                  

                  解决方案

                  Solved it. Answer belongs to @ckimbrell. "The problem looks like you are overwriting the variable $sqlresult with a new result that only returns 1 row. Try to change that in the nested loop."

                  include("connect.php");
                  
                  $sql = "SELECT * FROM sp_tickets WHERE user_id='foo'";
                  $sqlresult = mysqli_query($connect, $sql);
                  
                  $connectToStore = mysqli_connect("localhost", "root", "root", "root_db");
                  
                  if (mysqli_num_rows($sqlresult) > 0) {
                  while ($row = mysqli_fetch_array($sqlresult)) {
                  
                  $sqlStore = "SELECT * FROM transactions WHERE order_id='".$row['order_id']."'";
                  $sqlStoreDBResult = mysqli_query($connectToStore, $sqlStore);
                  
                  while ($rowTr = mysqli_fetch_array($sqlStoreDBResult)) {
                  
                      $id_str_array = $rowTr['items'];
                      $id_str_array = rtrim($id_str_array, ",");
                      $id_str_array = explode(',', $id_str_array);
                      foreach ($id_str_array as $key => $value) {
                          $id_quantity_pair = explode("-", $value); // Uses Hyphen(-) as delimiter to separate product ID from its quantity
                          $product_id = $id_quantity_pair[0]; // Get the product ID
                  
                          $sqlProduct = "SELECT * FROM products WHERE id='$product_id'";
                          $sqlresult2 = mysqli_query($connectToStore, $sqlProduct);
                          while ($pp_row = mysqli_fetch_array($sqlresult2)) {
                  
                              $tickets .= '<div class="holder">
                              <div data-ticket="' . $ticket . '" class="ticket">
                                  <div class="ticket-left">
                                      <span class="product-ticket left-span">' . $pp_row['product_name'] . ' ' . $pp_row['product_platform'] . ' ' . $pp_row['product_type'] . ' ' . $pp_row['product_region'] . '</span>
                                      <span class="ticket-no left-span">Ticket No. ' . $row['ticket_id'] . '</span>
                                      <span class="order-no left-span">Order No. ' . $row['order_id'] . '</span>
                                      <span class="left-span">Transaction No. ' . $rowTr['txn_id'] . '</span>
                                      <span class="product-region left-span">Region: ' . $pp_row['product_region'] . '</span>
                                  </div>
                                  <div class="ticket-right">
                                      <span class="created">Created: ' . $row['date'] . '</span>
                                  </div>
                                  <div class="ticket-bottom">
                                      <div class="bottom-holder">
                                          <span class="details"><span class="subject-txt">Category: </span>' . $row['category'] . '</span>
                                          <span class="details"><span class="subject-txt">Subject: </span>' . $row['subject'] . '</span>
                                          <span class="details desc">"' . $row['description'] . '"</span>
                                      </div>
                                  </div>
                              </div>
                              <div class="removeticketcontainer">
                                  <span class="removeticket">X</span>
                              </div>
                           </div>';
                              }
                          }
                      }
                  }
                  }
                  

                  这篇关于嵌套 while 循环只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:循环时我无法在里面创建 num 行 下一篇:找出数字序列中第一个缺失的数字

                  相关文章

                  最新文章

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

                    1. <legend id='KHno1'><style id='KHno1'><dir id='KHno1'><q id='KHno1'></q></dir></style></legend>

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

                    2. <tfoot id='KHno1'></tfoot>