pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="v9phddf" 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="n7p5nfh" 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="rr5bf5t" 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'>

                            主站蜘蛛池模板: 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 碳钢法兰厂家,非标法兰,定制异型,法兰生产厂家-河北九瑞管道 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 一体化污水处理设备,一体化污水设备厂家-宜兴市福源水处理设备有限公司 | 山东活动策划|济南活动公司|济南公关活动策划-济南锐嘉广告有限公司 | ALC墙板_ALC轻质隔墙板_隔音防火墙板_轻质隔墙材料-湖北博悦佳 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 板式换热器_板式换热器价格_管式换热器厂家-青岛康景辉 | 网站制作优化_网站SEO推广解决方案-无锡首宸信息科技公司 | 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 碎石机设备-欧版反击破-欧版颚式破碎机(站)厂家_山东奥凯诺机械 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 户外健身路径_小区健身器材_室外健身器材厂家_价格-浩然体育 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 超高频感应加热设备_高频感应电源厂家_CCD视觉检测设备_振动盘视觉检测设备_深圳雨滴科技-深圳市雨滴科技有限公司 | 进口试验机价格-进口生物材料试验机-西安卡夫曼测控技术有限公司 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 铸铁平台,大理石平台专业生产厂家_河北-北重机械 | 物流公司电话|附近物流公司电话上门取货 | 税筹星_灵活用工平台_企业财务顾问_财税法薪综合服务平台 | 篷房[仓储-婚庆-展览-活动]生产厂家-江苏正德装配式帐篷有限公司 | 空压机商城|空气压缩机|空压机配件-压缩机网旗下商城 | 保温杯,儿童婴童奶瓶,运动水壶「广告礼品杯定制厂家」超朗保温杯壶 | 岩棉切条机厂家_玻璃棉裁条机_水泥基保温板设备-廊坊鹏恒机械 | 「阿尔法设计官网」工业设计_产品设计_产品外观设计 深圳工业设计公司 | 耳模扫描仪-定制耳机设计软件-DLP打印机-asiga打印机-fitshape「飞特西普」 | 361°官方网站| 钢格栅板_钢格板网_格栅板-做专业的热镀锌钢格栅板厂家-安平县迎瑞丝网制造有限公司 | 汕头市盛大文化传播有限公司,www.11400.cc| 户外-组合-幼儿园-不锈钢-儿童-滑滑梯-床-玩具-淘气堡-厂家-价格 | 小青瓦丨古建筑瓦丨青瓦厂家-宜兴市徽派古典建筑材料有限公司 | 大立教育官网-一级建造师培训-二级建造师培训-造价工程师-安全工程师-监理工程师考试培训 | 安徽免检低氮锅炉_合肥燃油锅炉_安徽蒸汽发生器_合肥燃气锅炉-合肥扬诺锅炉有限公司 | 充气膜专家-气膜馆-PTFE膜结构-ETFE膜结构-商业街膜结构-奥克金鼎 | 制氮设备_PSA制氮机_激光切割制氮机_氮气机生产厂家-苏州西斯气体设备有限公司 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | 六自由度平台_六自由度运动平台_三自由度摇摆台—南京全控科技 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 云阳人才网_云阳招聘网_云阳人才市场_云阳人事人才网_云阳人家招聘网_云阳最新招聘信息 | 寮步纸箱厂_东莞纸箱厂 _东莞纸箱加工厂-东莞市寮步恒辉纸制品厂 |