简体   繁体   中英

counting total number of successful and failed upload in yii

My code looks like this right now. I want to add a total on the top of page that counts the total number of successful and failed data.

<?php echo $form->labelEx($model,'Upload File'); ?>

<?php echo $form->fileField($model,'csv_file'); ?>
<?php echo $form->error($model, 'csv_file'); ?><?php echo CHtml::submitButton('Submit'); ?><?php echo $form->errorSummary($model); ?><?php $this->endWidget();if (!empty($Results)) {
echo "<h3><font face='arial'><b> Upload Results </b></h3>";
echo implode(", ", $firstLine) . "<br/>";

foreach ($Results as $result) {
    echo implode(", ", $result["data"]) . "<br/>";
    echo "<div style='padding-left: 20px'>";
    echo "<span style='color: red;'>" . $result["message"] . "</span> <br/>";

    foreach ($result["model"]->getErrors() as $attribute => $errors) {
        echo "Attribute $attribute has the following errors:" . "<br/>";
        echo "<ul>";
        foreach ($errors as $error) {
            echo "<li style='color: red;'>" . $error . "</li>";

        }
        echo "</ul>";
    }
    echo "</div>";

}
}
?>
  • Total records
  • Total successful
  • Total failed

How do i do this? Is there anyway to do it in the view itself?

eval if this could be a solution

$numRecords = 0;
$numErrors = 0;
$numRecordsWithError = 0;
foreach ($Results as $result) {
    $numRecords++;

    echo implode(", ", $result["data"]) . "<br/>";
    echo "<div style='padding-left: 20px'>";
    echo "<span style='color: red;'>" . $result["message"] . "</span> <br/>";

    $flagRecErr = false;
    foreach ($result["model"]->getErrors() as $attribute => $errors) {
        if ($flagRecErr == false){
          $flagRecErr = true;
          $numRecordsWithError++;
        }
        $numErrors++;
        echo "Attribute $attribute has the following errors:" . "<br/>";
        echo "<ul>";
        foreach ($errors as $error) {
            echo "<li style='color: red;'>" . $error . "</li>";

        }
        echo "</ul>";
    }
    echo "</div>";

}
}
echo "<div>Num Records " .  $numRecords . "</div><br />";
echo "<div>Num Errors " .  $numErrors . "</div><br />";
echo "<div>Num Record with Errors " .  $numRecordsWithError . "</div><br />";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM