-1

I am comparing 1st [ Sent ] & 2nd column [ Last Update Date ] values. if 1st column value is greater than 2nd column value , than i want to save the value "attempted" in 3rd column [ Attempted ].

enter image description here

    <table> 
<tr>           
<th class="table-header">Sent</th>
<th class="table-header">Last Update Date</th> 

<th class="table-header">Attempted</th> 
</tr>

<?php
if(!empty($orderrecords))
    {
      foreach($orderrecords as $k=>$v)
      {  
?>

<tr>
<td><?php echo $orderrecords[$k]["sent_date"]; ?></td>         
<td><?php echo $orderrecords[$k]["lud"]; ?></td> 

<td>
<?php 
$orderrecords[$k]["sent_date"]= strtotime($orderrecords[$k]["sent_date"]);
$orderrecords[$k]["lud"]=  strtotime($orderrecords[$k]["lud"]);

$sqlecom = 'UPDATE table SET attempted = "attempted" WHERE $orderrecords[$k]["lud"] < $orderrecords[$k]["sent_date"]';
$db_handleecom = new DBController(); 
$resultecom = $db_handleecom->executeUpdate($sqlecom); 


echo $orderrecords[$k]["attempted"];
?>

</td> 
</tr>

<?php
 }
 }
?>  

</table>      

update : I tried below code, but still 3rd column values are not saving in database.

<?php 

$orderrecords[$k]["sent_date"]= strtotime($orderrecords[$k]["sent_date"]);
$orderrecords[$k]["lud"]=  strtotime($orderrecords[$k]["lud"]);

if ($orderrecords[$k]["lud"] < $orderrecords[$k]["sent_date"])
    {
    $sqlecom = 'UPDATE table SET attempted = "attempted"
               WHERE id = ' . $orderrecords[$k]['id'];

    $db_handleecom = new DBController(); 
    $resultecom = $db_handleecom->executeUpdate($sqlecom);
    //echo "attempted";
} 

echo $orderrecords[$k]["attempted"];

?>

Update 2 :

when i add below code on top of the file, than complete table disappears!!!! :

mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);

here is full code : https://pastebin.com/VwQSjgQ5

1 Answers1

0

Try this (I used same code structure you required) :

<table> 
  <tr>           
    <th class="table-header">Sent</th>
    <th class="table-header">Last Update Date</th> 
    <th class="table-header">Attempted</th> 
  </tr>
<?php
  if(!empty($orderrecords)){
    foreach($orderrecords as $k=>$v){  
?>
<tr>
<td><?php echo $v["sent_date"]; ?></td>         
<td><?php echo $v["lud"]; ?></td> 
<?php 
  if ($v["lud"] < $v["sent_date"])  {
    $attempted= "attempted";
    $sqlecom = 'UPDATE table SET attempted = "attempted" WHERE ORDERID = '.$v["order_id"];
    $db_handleecom = new DBController(); 
    $resultecom = $db_handleecom->executeUpdate($sqlecom);
  }  
  else {
    $attempted = "";
  }

?>
<td><?php echo $attempted; ?></td> 
</tr>

<?php
    }
  }
?>  
</table>
Amani Ben Azzouz
  • 2,477
  • 3
  • 15
  • 26