doubomudichen0832 2014-04-08 10:06
浏览 21

使用javascript继续或进入PHP循环

I am in a interesting problem. There is a foreach loop, this loop insert data into mysql table form a excel file for every row in excel file. Sometimes duplicate data comes out from excel which is natural. When this duplicate data attempt to insert, I want a popup to ask user that he is interested to insert duplicate data or not. If yes the rest of the code in PHP foreach loop will execute otherwise it will continue with next loop. Please help.

  • 写回答

1条回答 默认 最新

  • douhu2890 2014-04-08 10:25
    关注

    In PHP you need to process the excel file and halt processing when you see a duplicate and store the current position of the file perhaps in session. Your code should look at this flag to alert the user with popup. Once the user selects yes, you move the position in file and continue processing. This could be achieved with AJAX or without through multiple submissions.

    Here is some pseudo code:

    // is there a current saved pos?
    $pos = getSavedPos();   
    if ($pos) {
        moveToPos($pos);
    }
    
    // process file
    while (!$endOfFile) {
        $pos        = getCurrentPosOfFile();
        $data       = getRowData();
        $duplicate = isDuplicateData($data);
        if ($duplicate) {
            savePos($pos);
            break;
        }
        else {
            insertDataIntoDb($data);
        }
    }
    
    // code elsewhere
    if ($duplicate) {
        alert('This file contains duplicate information. Do you wish to continue?');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题