如果不改变内部div的颜色?

时间:2016-02-15 10:20:09

标签: javascript php jquery html

在下面的代码中我试图上传csv file.its working.what我想知道的是当csv成功上传为绿色并且当它没有上传为红色时我怎么能改变main-div的颜色?

这是我的代码

<div id="main-div" class="content bg-gray-lighter">

        <h3 class=" pull-right"><a href="<?php echo $one->assets_folder; ?>/download/sample_csv.csv"><span class="label label-warning"><i class="fa fa-download "></i> Download Sample Format Here <i class="fa fa-file-excel-o "></i> </span></a></h3>
        <?php
        include "../classes/connection.php"; //Connect to Database
        //Upload File
        if (isset($_POST['submit'])) {

            $deleterecords = "UPDATE TABLE data"; //empty the table of its current records
            mysql_query($deleterecords);
            $product = $_POST['product'];
            $courier = $_POST['courier'];
            $billmonth = $_POST['billmonth'];
            $billyear = $_POST['billyear'];
            $billrun = $_POST['billrun'];
            $dispatchtype = $_POST['dispatchtype'];
            $Received_Date=$_POST['Received_Date'];

            if (is_uploaded_file($_FILES['filename']['tmp_name'])) {

                echo "<div id='main-div' class='block-content block-content-full bg-success text-white-op'>";
                echo "<p>Displaying contents:</p>";
                echo "<p>Product - <strong style='color: #ffc128'>".$product. " </strong> Service Provider - <strong style='color: #ffc128'>".$courier. "</strong> Bill Month - <strong style='color: #ffc128'>".$billmonth. " </strong> Bill Year - <strong style='color: #ffc128'>".$billyear. "</strong> Bill Run- <strong style='color: #ffc128'>" .$billrun. " </strong> Dispatch Type - <strong style='color: #ffc128'>".$dispatchtype."</strong></p><br/>";
                echo "<span style='color:#feffa4'>";
                readfile($_FILES['filename']['tmp_name']);
                echo "</span>";
            }

            //Import uploaded file to Database
            $handle = fopen($_FILES['filename']['tmp_name'], "r");
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

                $linecount++ == count(file('filename.csv'));
                $data[2] = date('Y-m-d', strtotime($data[2]));
                $data[5] = date('Y-m-d', strtotime($data[5]));

                if (($product==$data[0]) && ($courier==$data[1]) && (strcasecmp($billmonth,$data[6])==0) && ($billyear==$data[7]) && ($billrun==$data[8]) && ($dispatchtype==$data[9])) {

                    $import = "INSERT into data(Product,Courier,Received_Date,Acc_No,Received_By,Delivered_Date,Month,Year,Bill_Run,Dispatch_Type,Status,Bounce_Code) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]')";
                }
                else {

                    echo " <br/> <br/>Data Error.<br/>";
                    echo "  <br/><br/><a href='javascript:history.go(-1)' class='btn btn-sm btn-primary'><i class='si si-action-undo'></i> Go Back and Upload Again</a> <br/> <br/>";
                }
                    mysql_query($import) or die(mysql_error());
            }
        fclose($handle);
            ?>

            <?php
            echo "<br/><br/><br/>";
            print "$linecount Records have been Imported ";
            echo "  <br/><br/><a href='javascript:history.go(-1)' class='btn btn-sm btn-primary'><i class='si si-action-undo'></i> Go Back and Upload Again</a> <a href='index.php' class='btn btn-sm btn-primary'><i class='si si-home'></i> Home</a>  <br/> <br/>";

        //view upload form
         echo "</div>";
        } else {  ?>

2 个答案:

答案 0 :(得分:0)

您需要做的是创建两个CSS类,每个类用于成功上载和不成功上传。例如,

.uploadSuccess {
 background-color: green;
}

.uploadFail {
 background-color: red;
}

然后,您可以在客户端或服务器端代码中将div的类设置为其中之一,无论您在何处决定上传是否成功。

答案 1 :(得分:0)

最好的方法是划分观点和逻辑。思考并阅读Model View Controller architecture

如果你想点内联 - 你只需要在上传成功时填写一个变量(例如$bUploadSuccessful = true)并设置相关的css类。

在呈现模板之前,您必须重新格式化代码以执行所有逻辑。