-3

对于为什么这不起作用,这有点令人困惑。我可以做一个工作,但有什么想法吗?它将上传的 CSV 与数据库中的配置相匹配。仅返回前 5 列。其余的,用户指定的(应该打印 Echo)不显示。

$csv_col while 循环 = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 45 46 47 48 49

$getConfiguration[0] =

数组( [config_key] => 22 [config_client_ident] => 105 [config_s_timestamp] => 1378008000 [config_e_timestamp] => [config_kpi_1] => 81 [config_kpi_2] => 82 [config_kpi_3] => 83 [config_kpi_4] => 84 [ config_kpi_5] => [config_kpi_6] => [config_kpi_7] => [config_kpi_8] => [config_kpi_9] => [config_kpi_10] => [config_kpi_11] => [config_kpi_12] => [config_kpi_13] => [config_kpi_14] => [ config_kpi_15] => [config_kpi_16] => [config_kpi_17] => [config_kpi_18] => [config_kpi_19] => [config_kpi_20] => [config_kpi_21] => [config_kpi_22] => [config_kpi_23] => [config_kpi_24] =>[config_kpi_25] => [config_kpi_26] => [config_kpi_27] => [config_kpi_28] => [config_kpi_29] => [config_kpi_30] => [config_kpi_31] => [config_kpi_32] => [config_kpi_33] => [config_kpi_34] => [config_kpi_35] => [config_kpi_36] => [config_kpi_37] => [config_kpi_38] => [config_kpi_39] => [config_kpi_40] => [config_kpi_41] => [config_kpi_42] => [config_kpi_43] => [config_kpi_44] => [config_kpi_45] => [config_kpi_46] => [config_kpi_47] => [config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_28] => [config_kpi_29] => [config_kpi_30] => [config_kpi_31] => [config_kpi_32] => [config_kpi_33] => [config_kpi_34] => [config_kpi_35] => [config_kpi_36] => [config_kpi_37] => [config_kpi_38] => [config_kpi_39] => [config_kpi_40] => [config_kpi_41] => [config_kpi_42] => [config_kpi_43] => [config_kpi_44] => [config_kpi_45] => [config_kpi_46] => [config_kpi_47] => [config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_28] => [config_kpi_29] => [config_kpi_30] => [config_kpi_31] => [config_kpi_32] => [config_kpi_33] => [config_kpi_34] => [config_kpi_35] => [config_kpi_36] => [config_kpi_37] => [config_kpi_38] => [config_kpi_39] => [config_kpi_40] => [config_kpi_41] => [config_kpi_42] => [config_kpi_43] => [config_kpi_44] => [config_kpi_45] => [config_kpi_46] => [config_kpi_47] => [config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_35] => [config_kpi_36] => [config_kpi_37] => [config_kpi_38] => [config_kpi_39] => [config_kpi_40] => [config_kpi_41] => [config_kpi_42] => [config_kpi_43] => [config_kpi_44] => [config_kpi_45] => [config_kpi_46] => [config_kpi_47] => [config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_35] => [config_kpi_36] => [config_kpi_37] => [config_kpi_38] => [config_kpi_39] => [config_kpi_40] => [config_kpi_41] => [config_kpi_42] => [config_kpi_43] => [config_kpi_44] => [config_kpi_45] => [config_kpi_46] => [config_kpi_47] => [config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)[config_kpi_48] => [config_kpi_49] => [config_kpi_50] =>)

$csvRead[0]

数组([0] => 数据日期 [1] => 代理 IDENT [2] => 客户 IDENT [3] => 位置 IDENT [4] => 程序 IDENT [5] => xx VSAT [6] => xx SWSAT [7] => xx NSODS [8] => xx SWDSAT )

从查询返回

数组([0] => 数组([key_id] => 84 [key_enabled] => 1 [key_name] => xx SWDSAT [key_desc] => xx CSAT 有些不满意)

)

// Build the check arary
    $checkArray = array("Data Date", "Agent IDENT", "Client IDENT", "Location IDENT", "Program IDENT");
    $fileVerification = true;
    $config_col = 1;

    // Loop through the 50 available columns
    while($config_col <= 50){
        $csv_col = $config_col - 1;
        print $csv_col . " ";
        // Make sure something is in those columns
        if($getConfiguration[0]['config_kpi_'.$config_col] != ''){
            // There is, now lets query and get those names.
            $getNamesQuery[] = "SELECT * FROM kpi_keys WHERE key_id=".$getConfiguration[0]['config_kpi_'.$config_col];
            $getNamesResult = dbInsert($getNamesQuery);
            // Compare the first 5 columns
            if($csv_col < 5){
                if($csvRead[0][$csv_col] == $checkArray[$csv_col]){
                    $output .= '<div class="messageGood"> - '.$csvRead[0][$csv_col].' column verified.</div>';
                } else {
                    $output .= '<div class="messageBad"> - Column "'.$csvRead[0][$csv_col].'" did not match "'.$checkArray[$csv_col].'" in the current configuration.</div>';
                    $fileVerification = false;
                }
            } else {
                // Now lets compare the customizable columns. We're going to do names and ID's to make sure.
                print "Echo";
            }
            $getNamesQuery = null;
        }
        $config_col++;
    }

    // Now we check the information

    print "<pre>";
    print_r($getConfiguration[0]);
    print_r($csvRead[0]);
    print_r($getNamesResult);
    print "</pre>";

回答(感谢 Wrikken)

// Loop through the 50 available columns
    while($config_col <= 50){
        $csv_col = $config_col - 1;
        $partOne = '';
        $partTwo = '';
        // Make sure something is in those columns
        // Compare the first 5 columns
        if($csv_col < 5){
            if($csvRead[0][$csv_col] == $checkArray[$csv_col]){
                $partOne .= '<div class="messageGood"> - '.$csvRead[0][$csv_col].' column verified.</div>';
            } else {
                $partOne .= '<div class="messageBad"> - Column "'.$csvRead[0][$csv_col].'" did not match "'.$checkArray[$csv_col].'" in the current configuration.</div>';
                $fileVerification = false;
            }
        }
        if($getConfiguration[0]['config_kpi_'.$config_col] != ''){
            print $csv_col . " ";
            // There is, now lets query and get those names.
            $getNamesQuery[] = "SELECT * FROM kpi_keys WHERE key_id=".$getConfiguration[0]['config_kpi_'.$config_col];
            $getNamesResult = dbInsert($getNamesQuery);
            // Now lets compare the customizable columns. We're going to do names and ID's to make sure.
            $partTwo = "Comparison";
            $getNamesQuery = null;
        }
        $config_col++;
    }
    $output .= $partOne . $partTwo;
4

1 回答 1

0
 while($csv_col < 5){
                if($csvRead[0][$csv_col] == $checkArray[$csv_col]){
                    $output .= '<div class="messageGood"> - '.$csvRead[0][$csv_col].' column verified.</div>';

如果只运行一次,如果你想连接使用while,它将运行..直到结束。

于 2013-09-23T18:51:29.167 回答