Thursday, January 9, 2020

Get Weekly data using PHP MYSQLI

<table id="example" class="table table-striped table-bordered wely_tableset" style="width:100%">
<thead> 
<tr>
            <th style="line-height: 20px;border-right-color: #000;" colspan="2" class="tble_fb">For the week of Tuesday:</th>
            <th style="line-height: 50px;border-right-color: #000;" colspan="2" class="tble_fb"><?php date_default_timezone_set('Canada/Eastern'); $tuesday_date = date("m/d/Y", strtotime("previous tuesday"));
//echo $tuesday_date; echo '***';
$past_tuesday = date("d-M-Y", strtotime( "$tuesday_date -7 day" ) );
echo $past_tuesday; ?></th>
            <th colspan="2" style="border-right-color: #000;" class="tble_fb sdfrds">To Tuesday:
<span class="tblspn">Items Info</span>
</th>
            <th style="" colspan="3" class="tble_fb sdfrds"><?php  $tuesday_date = date("d-M-Y", strtotime("previous tuesday"));
echo $tuesday_date;
 ?>
<span class="tblspn">Payment Info</span>
</th>
        </tr>
<tr>                     
    <td class="heading_cls">Order Id</td>
        <td class="heading_cls">Order Status</td>
        <td class="heading_cls">Refer By</td>
    </tr>
</thead>
<tbody>
<?php
$servername = "localhost";
$username = "xxxx";
$password = "xxxx(*()";
$dbname = "xxxx";
date_default_timezone_set('Canada/Eastern');
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
  $start_date_week = new DateTime('-7');
  $current_date_week = $start_date_week->format('m/d/Y');
  //echo $current_date_week;echo '****';
  $dt = date("m/d/Y");
  $day_date_future = date("m/d/Y", strtotime( "$dt -7 day" ) );
 //echo $day_date;die('hhhhhhhhhhh');

 $tuesday_date = date("m/d/Y", strtotime("previous tuesday"));
//echo $tuesday_date; echo '***';
$past_tuesday = date("m/d/Y", strtotime( "$tuesday_date -7 day" ) );
//echo $past_tuesday;
 
$sql_package = "SELECT * from xxxxx WHERE order_status_type='Completed' AND order_complete_date and ('$past_tuesday' AND '$tuesday_date') order by id";


$result = $conn->query($sql_package);

$val_price = 0;

if ($result->num_rows > 0) {
    while($row_pack = $result->fetch_assoc()) {
?>
<tr>                     
    <td class="heading_cls size_sett"><?php $order_id_pac = $row_pack["order_id"];echo $order_id_pac; ?></td>
        <td class="heading_cls" style="background:#c6e0b3;"><?php echo $row_pack["order_status_type"]; ?></td>
        <td class="heading_cls size_sett"><?php echo '$'.$row_pack["package_total"]; $val_price += $row_pack["package_total"];?></td>
    </tr>
<?php
    }
} else {
   // echo "0 results";
}
?>
 <tr>

<td style="border-left: none !important;border-right: none !important;font-size:0px;">Total</td>
<td style="font-weight:bold;">Total</td>
<td style="font-weight:bold">$<?php echo number_format($val_price); ?></td>
</tr>
</tbody>

</table>

No comments:

Post a Comment