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

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

        <legend id='ImW71'><style id='ImW71'><dir id='ImW71'><q id='ImW71'></q></dir></style></legend>
      1. <small id='ImW71'></small><noframes id='ImW71'>

        運行while循環時的進度條

        Progress bar while running while loop(運行while循環時的進度條)
          <tbody id='MnlCs'></tbody>

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

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

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

                  本文介紹了運行while循環時的進度條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有這個 while 循環,它基本上遍歷數據庫中的大量記錄,并將數據插入另一個:

                  I have this while loop, that basically loops through a lot of records in a database, and inserts the data in another:

                  $q = $con1->query($users1) or die(print_r($con2->errorInfo(),1));
                  while($row = $q->fetch(PDO::FETCH_ASSOC)){
                      $q = $con2->prepare($users2);
                      $q->execute(array($row['id'], $row['username'])) or die(print_r($con2-errorInfo(),1));
                  }
                  

                  (為了便于閱讀,腳本已被縮短 - 正確的有更長的數組)

                  我想做這個更圖形化的,并顯示一個進度條,它已經走了多遠,而不是只看到頁面加載幾分鐘(這個頁面有大約 20.000 行 - 我有很多表格更多數據)

                  I would like to do this more graphical, and show a progress bar on how far it has went, instead of just seeing a page loading for a few minutes (there are ~20.000 rows in this one - I have tables with much more data)

                  我知道您可以從舊數據庫中獲取總數,而且我還可以輕松地將當前數字放入這樣的變量中:

                  I get that you could get the total number from the old database, and I could also easily put the current number into a variable like this:

                  $q = $con1->query($users1) or die(print_r($con2->errorInfo(),1));
                  $i = 0;
                  while($row = $q->fetch(PDO::FETCH_ASSOC)){
                      $q = $con2->prepare($users2);
                      $q->execute(array($row['id'], $row['username'])) or die(print_r($con2-errorInfo(),1));
                      $i++;
                  }
                  

                  但現在我需要實際獲取 $i 并顯示它 - 或者類似的東西.

                  But now I need to actually fetch $i and display it - or something like it.

                  這是如何輕松"完成的?

                  How is this "easily" done?

                  進度條的代碼可以在與 while 循環相同的文檔中,也可以在另一個更簡單的文檔中.

                  The code for the progress bar can either be in the same document as the while loop, or in another if easier.

                  推薦答案

                  您可以創建一個主"文件,該文件對第一個文件執行 ajax 以運行單個查詢.您可以獲取此主文件中的所有條目 ID,然后將其作為參數傳遞給執行單個查詢的第二個文件.將這些 ID 存儲在一個 javascript 數組中.

                  You can do a "master" file that does an ajax to this first file to run a single query. You could get all the entry id's in this master file, and then pass it as a parameter to the second file that does a single query. Store these ids in a javascript array.

                  創建一個執行此操作的函數,當第一個ajax完成時,移動到id數組的第二個元素,并使用第二個參數執行另一個ajax.順便說一下,這就是 magento 導入的方式:)

                  Create a function that does this, and when the first ajax is done, move to the second element of the id array, and do another ajax with a second parameter. That's how magento imports are done by the way :)

                  如果您需要進一步解釋,請告訴我,我已盡力解釋,但可能不是很清楚.

                  If you need further explanations, let me know, I tried my best to explain, but may have not been perfectly clear.

                  // you generate this javascript array using php.
                  // let's say you have all the ids that have to be processed in $Ids php array.
                  Ids = [<?php echo implode(',', $Ids); ?>];
                  
                  function doAjax(i) {
                      $.ajax({  // using jquery for simplicity
                          'url': "ajax.php?id=" + Ids[i],
                      }).done(function(){
                          if ( i >= 0 ) {
                              // at the point you know you're at ((Ids.length-i)/(Ids.length) * 100) percent of the script
                              // so you can do something like this:
                              // $('.progressbar').css('width', ((Ids.length-i)/(Ids.length) * 100) + '%');
                              doAjax(i-1);
                          }
                      });
                  }
                  
                  doAjax(Ids.length); // starting from the last entry
                  

                  所以,只是為了解釋它的作用.它首先聲明一個全局 javascript 數組,其中包含需要更改的所有 ID.

                  So, just to explain what this does. It starts by declaring a global javascript array that has all the ids that will need to be changed.

                  然后我聲明了一個遞歸的ajax函數,這樣我們就可以確保在任何時候只有一個ajax運行(這樣服務器不會炸毀),并且我們可以有一個相當準確的進度.此 ajax 函數執行以下操作:

                  Then I declare a recursive ajax function, this way we can make sure that only one ajax runs at any single time (so the server doesn't blow up), and we can have a fairly accurate progress. This ajax function does the following:

                  • 向 ajax.php?id=xxx 發送請求 - 其中 xxx 是 javascript 數組中的 id 之一.
                  • 在文件中,我們獲得了 id ($_GET['id']),您從舊數據庫中取出它,并將其插入到新數據庫中.這僅適用于一個條目.
                  • 當 ajax 完成時,它轉到 done() 函數.由于我們從最后一個元素開始 doAjax() 函數,因此我們執行下一次迭代 doAjax(i-1).由于我們在數組中倒退,我們檢查鍵是否為正.如果不是,腳本將停止.
                  • Sends a request to ajax.php?id=xxx - where xxx is one of the ids in the javascript array.
                  • In the file, we get the id ($_GET['id']), you take it from the old database, and insert it in the new one. This is only for one entry.
                  • when the ajax is done, it goes to the done() function. Since we start the doAjax() function with the last element, we do the next iteration doAjax(i-1). Since we're going backwards in the array, we check if the key is positive. If it's not, the script will stop.

                  就是這樣.

                  這篇關于運行while循環時的進度條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                    <tbody id='q4iAB'></tbody>

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

                        <bdo id='q4iAB'></bdo><ul id='q4iAB'></ul>
                      • <tfoot id='q4iAB'></tfoot>
                          • <small id='q4iAB'></small><noframes id='q4iAB'>

                            主站蜘蛛池模板: 成人免费片 | 亚洲第一av网站 | 羞羞视频免费观 | 日本超碰| 黄色片免费看视频 | 成人国产精品久久久 | 国产精品视频一区二区三区 | 丁香综合 | 久久精品女人天堂av | 国产成人精品区一区二区不卡 | 国产午夜视频 | 一级黄色片毛片 | 欧美性生活一区二区三区 | 国产小网站 | 国产高清精品一区二区三区 | 天堂va在线观看 | 国产精品美女久久久久久久网站 | 精品久草 | 色精品视频| 欧美日本免费 | 中文字幕成人 | av毛片 | 国产区一区 | 久久高清 | 99久久精品免费看国产四区 | 欧美精品在线免费 | 伊人网99 | 亚洲精品乱码久久久久久9色 | 超碰在线人人干 | 无码日韩精品一区二区免费 | 黄色a三级 | 91美女在线观看 | 久久久精| 国产美女精品 | 国产一区二区欧美 | 99精品亚洲国产精品久久不卡 | 国产精品一区二区久久久久 | 自拍视频在线观看 | 国内精品在线视频 | 视频在线观看一区二区 | 亚洲视频www |