How do i do that?

How do I make it when I add a qty number, say that qty number have been added from this date or say have been update qty number from this date?
For example, there are 32 in the database and I add 5 more and that say 5 more were added on this date

2022-09-24_150848


source

<?php include_once 'header.php'; ?>
<?php include_once 'sidebar.php'; ?>
<?php include_once 'navtop.php'; ?>
<?php
if ($_SESSION['admin_type'] != "admin") {
  header("Location: addPatient.php?add");
}
 $del = output(@$_GET['del']);
if(isset($del) && $del!=""){
  if(isset($_SESSION['admin_type'])) {
    if($_SESSION['admin_type'] == 'admin') {
     $stm = $db->prepare("DELETE FROM implant WHERE id=:id");
     $stm->bindParam(":id", $del, PDO::PARAM_STR);
     $stm->execute();
     re("success"," thank you "," deleted successfully. ");
     direct("imp_list.php");
    }
   }
 }
 ?>
                <div class="container-fluid">
                  <div class="card shadow mb-4">
                    <div class="card-header py-3">
                      <h6 class="m-0 font-weight-bold text-gray-800">Implant System</h6>
                    </div>
                   <div class="card-body">
                     <?php
                     $stm = $db->prepare("SELECT * FROM implant ORDER BY id ASC");
                     $stm->execute();
                     $rowCount = $stm->rowCount();
                     if($rowCount > 0){
                     ?>
                     <div class="table-responsive">
                         <table class="table table-bordered" cellspacing="0" id="datatl">
                             <thead>
                                 <tr>
                                     <th>#</th>
                                     <th>Type</th>
                                     <th>Quantity</th>
                                     <th>add Quantity</th>
                                     <th>Update Qty Date</th>
                                     <th>Registration Date</th>
                                     <th>Action</th>
                                 </tr>
                             </thead>
                             <tbody>
                               <?php
                               $nu = 0;
                               while($row = $stm->fetch(PDO::FETCH_ASSOC)) {
                                 ?>
                                 <tr>
                                     <td><?php echo $row['id']; ?></td>
                                     <td><?php echo $row['type']; ?></td>
                                     <td>
                                       <?php
                                       if ($row['qty'] <= 5) {
                                         echo '<span class="badge badge-pill badge-danger">'.$row['qty'].' دانە</span>';
                                       }elseif ($row['qty'] > 5 AND $row['qty'] <= 10) {
                                         echo '<span class="badge badge-pill badge-warning">'.$row['qty'].' دانە</span>';
                                       }else {
                                         echo '<span class="badge badge-pill badge-success">'.$row['qty'].' دانە</span>';
                                       }
                                        ?>
                                     </td>
                                     <td>
                                       <input type="hidden" class="pid" value="<?= $row['id'] ?>">
                                       <input type="number" class="form-control itemQty" value="<?= $row['qty'] ?>" style="width:75px;">
                                     </td>
                                     <td><?php echo $row['update']; ?></td>
                                     <td><?php echo $row['date_created']; ?></td>
                                     <td>
                                       <a href="edit_implant.php?id=<?php echo htmlentities($row['id']);?>" class="btn btn-warning btn-sm"><i class="fa fa-edit"></i></a>
                                       <a href="imp_list.php?del=<?php echo $row['id']; ?>" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                                     </td>
                                 </tr>
                                 <?php $nu++;}?>
                             </tbody>
                         </table>
                     </div>
                     <?php
                     }else {
                       echo 'not avalable';
                     }
                      ?>
                  </div>
                </div>
              </div>
              <script type="text/javascript">
              $(document).ready(function() {

                // Change the item quantity
                $(".itemQty").on('change', function() {
                  var $el = $(this).closest('tr');

                  var pid = $el.find(".pid").val();
                  //var pprice = $el.find(".pprice").val();
                  var qty = $el.find(".itemQty").val();
                  location.reload(true);
                  $.ajax({
                    url: 'action.php',
                    method: 'post',
                    cache: false,
                    data: {
                      qty: qty,
                      pid: pid
                      //pprice: pprice
                    },
                    success: function(response) {
                      console.log(response);
                    }
                  });
                });

              });
              </script>
<?php include_once 'footer.php'; ?>

You would need a History table that records what modifications you made and when.

1 Like

can you give more information?

A history table. A table that records what you modified, to what, and when. Another table in the database whose sole purpose is to record these changes and generally take up space, usually without a solid reasoning behind it.

This is a lesson in storing the data relevant to what you’re going to be asking about.

Let’s take your example.

We’ve got… turkry. Which sounds like a bad chinese accent to me, but… moving on. We’ve got a product. We keep track of how much of it we have in stock.
We’ll start with 32.
Next, we sell 5 of them.
Now our table just tells us how many we have in stock. So that’s 27. We put 27 in our table.
The delivery truck comes in. We’ve got 12 more products now.
We’ve updated our stock, so… 39. We put 39 in our table.

Boss comes by. Asks how many have we sold?

We can’t answer the boss with the information we have. We can only tell him, we’ve got 39 products in stock.

We’ve stored the wrong information for the question being asked. It’s compact information; we’re only storing 1 number for the products, and if the only question we’re going to be asked is how many we have left in stock, we’re good.

But the boss is going to ask about how many we’ve sold. So we need more information stored. Let’s go back to the beginning.

We’ve got 32 products.
We sell 5. Our stock table now says 27. We also write down that we sold 5 on Tuesday in a changes table.
Delivery truck comes in. Our stock table now says 39.

Boss asks us how many we’ve sold. We look at our changes table. It says 5. We can answer the boss’ question.
Boss then asks how many we had delivered. Silly boss, always asking new questions. What could we have done to be able to answer the boss’ second question?

1 Like

are you mean this?
link

Yeah pretty much. A history table, an audit table, take your pick on terms. As long as it records what you need it to record…

thanks a lot, i will try it.

Not exactly. Yes, you do need an inventory table to hold a new row for each transaction that affects the receiving/loss of the quantity of items and order/order_item tables to hold the information about the quantity of items ‘consumed’, but the rows in these tables are the primary information being recorded and should already contain all the Who, What, When, Where, and Why information about each operation that affects the quantity of an item, without storing any redundant information. The linked to article deals with edits/updates made to primary information recorded in tables, not the recording of the primary information itself. The distinction between these being recording (inserting) new information vs editing/updating existing information.

Normally all this information should be held in a table called invoices which contains, how surprising, the invoices. Outgoing for sells and ingoing for buys.

can anyone write syntax code to understand it clearly?

No one is going to do you for it. If you make an attempt someone should be able to help you with it.