更新除最后一个数组之外的数组中的所有值的时间戳

时间:2015-08-11 18:39:30

标签: php mysqli

<?php
session_start();
?>
<html>
        <head>  
               <link rel="stylesheet" href="css/bootstrap.css"> 
             <script type="text/javascript">
                       function submit() {
                                            document.getElementById("myform").submit();
                                          }
                       window.onload = function() {
                                                   document.getElementById("textbox").focus();
                                                 };
                       function upflag(){
                        <?php
                             session_start();
                             $host="localhost";
                             $user="root";
                             $password="";
                             $db="greenmobiles";
                             $table="manifest";
                             $con=mysqli_connect("$host","$user","$password") or die("Cannot Connect");
                             mysqli_select_db($con,"$db") or die("Cannot select DB!");    
                             $d='document_no';
                             $a='awb_no';
                             $createdate= date('Y-m-d H:i:s');
                             echo var_dump($_SESSION['arr2']);
                            foreach ($_SESSION['arr2'] as $key => $value)
                             {
                              $tmp1=$value[$a];
                              $tmp2=$value[$d];
                              $query = "UPDATE manifest SET flag = '$createdate' WHERE (awb_no = '$tmp1') AND (document_no = '$tmp2' )";
                              $result2=mysqli_query($con,$query) or die(mysqli_error($con));
                             }
                        ?>

                       }
                </script>
        </head>
     <body>
     <div class="jumbotron" style="height:50px;">
  <h3 style="margin-top:0px; margin-left:30px;">GREEN MOBILES</h3>
  </div>
      <form class="form-inline" style="padding-top:20px;margin-left: 50px;" id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
         <div class="form-group">
<label for="textbox">Document No.</label>
      <input class="form-control" type="text" id="textbox" name="excel" onchange="submit()">
      </div>
      </br>
      </form>
        <?php
             error_reporting(E_ALL); ini_set('display_errors', 1);

             $vars = $_COOKIE['var1'];
             if(!isset($_SESSION['items'])) {
                 $_SESSION['items'] = array();

                }            
            if(!isset($_SESSION['arr2'])) {
                $_SESSION['arr2'] = array();
                }
                 if(!isset($alpha)) {
                $alpha = array();
                }
             $var='';
            if(isset($_POST['excel']))
            {
             $host="localhost";
         $user="root";
         $password="";
         $db="greenmobiles";
         $table="manifest";
         $var=$_POST['excel']; 
          $datas=$_SESSION['items'];

                 $d='document_no';
                 $a='awb_no';
                 $o='order_id';
                 $f='forms';
                 $e='extras'; 

         $con=mysqli_connect("$host","$user","$password") or die("Cannot Connect");
         mysqli_select_db($con,"$db") or die("Cannot select DB!");    
               if (in_array($var,$_SESSION['items']))
             {
                    echo "<script>alert('oops! This item has already been scanned!')</script>";
                 }
                 else
                 {
                   $sql = "SELECT * FROM manifest WHERE awb_no = '$var'";
                   $result = mysqli_query($con,$sql);  
                       if(mysqli_num_rows($result) > 0) 
                       {
                         echo " ";
                       } 
                       else 
                       {$alpha=$_SESSION['arr2'];
                         echo "<script>alert('Tracking id is not present in the manifest!')</script>";
                         echo '<span style="margin-left:150px;font-weight: bold;">'.'<b>The details of the currently scanned items are given below:</b><br><hr>'.'</span>';
                         echo '<div class="col-lg-10 col-lg-offset-1 panel">'."<table class='table'>
                       <tr>
                           <th>Document No</th>
                           <th>AWB NO</th>
                           <th>Order Id</th>
                           <th>Forms</th>
                           <th>Extras</th>
                      </tr>";
                         foreach( $alpha as $key => $obj)
                        {
                           echo "<tr>"; 
                           echo "<td> ". $obj[$d] ."</td>";
                           echo "<td> ". $obj[$a] ."</td>";
                           echo "<td> ". $obj[$o] ."</td>";
                           echo "<td> ". $obj[$f] ."</td>";
                           echo "<td> ". $obj[$e] ."</td>";
                           echo "</tr>";  
                          }    
                       }
                 $sqli = "SELECT * FROM manifest WHERE (awb_no = '$var') AND (document_no='$vars')";
                 $result1 = mysqli_query($con,$sqli);  
                 if (mysqli_num_rows($result1)) 
                   {
                     echo " ";
                   }
                 else
                   {
                     echo "<script>alert('Tracking id does not belong to the document number entered.')</script>";
                     exit(0);
                   } 
                 while ($row = mysqli_fetch_assoc($result))
                  {

                    $_SESSION['arr1'][] = $row;
               $_SESSION['arr2'] = $_SESSION['arr1'];

                $_SESSION['data'][] = $row['awb_no'];
                $_SESSION['items'] = $_SESSION['data'];
                   }
                }

               $alpha=$_SESSION['arr2'];
                 echo '<span style="margin-left:150px;font-weight: bold;">'.'<b>The details of the currently scanned items are given below:</b><br><hr>'.'</span>';
                 echo '<div class="col-lg-10 col-lg-offset-1 panel">'."<table class='table'>
                       <tr>
             <th>Document No</th>
                       <th>AWB NO</th>
               <th>Order Id</th>
             <th>Forms</th>
             <th>Extras</th>
             </tr>";
             foreach( $alpha as $key => $obj)
                        {
                        echo "<tr>"; 
                        echo "<td> ". $obj[$d] ."</td>";
                         echo "<td> ". $obj[$a] ."</td>";
                         echo "<td> ". $obj[$o] ."</td>";
                          echo "<td> ". $obj[$f] ."</td>";
                         echo "<td> ". $obj[$e] ."</td>";
                           echo "</tr>";  
                          }  echo "</table></div>";    
              echo "<div style='padding-top:25px;text-align:center;'>"."<a href='hopepdf.php' class='btn btn-primary btn-lg' role='button' onclick='upflag()'>"."Download as PDF"."</a></div>";
              }      
              else
                  {
                    session_destroy();
                  }
?>
</body>
</html>    

当我执行查询时,除了会话数组的最后一个值之外,数据库中会话数组的所有值都会更新时间戳。我似乎没有得到这里的问题。感谢任何形式的帮助。谢谢。

0 个答案:

没有答案