Skip to content
Advertisement

PHP MYSQL Displaying the same data from table to another page

<div class="card-header py-3">
          <h4 class="m-2 font-weight-bold text-primary">Asset Approval List</h4>
        </div>

        <div class="card-body">
          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0"> 
           <thead>
               <tr>
                 <th>Asset</th>
                 <th>Serial Number</th>
                 <th>Model Name</th>
                 <th>Owner ID</th>
                 <th>Owner Name</th>
                 <th>Description</th>
               </tr>
           </thead>
      <tbody>
    
    <script>
    function approval(){
      window.location.href = "AddAssetApproval.php";
    }
    </script>

<?php    
            
$query = "SELECT * FROM waiting_approval";
$result = mysqli_query($conn, $query) or die (mysqli_error($conn));

while ($row = mysqli_fetch_assoc($result)) {
                     
    echo '<tr>';
    echo '<td>'. $row['Category'].'</td>';
    echo '<td>'. $row['SerialNumber'].'</td>';
    echo '<td>'. $row['ModelName'].'</td>';
    echo '<td>'. $row['OwnerID'].'</td>';
    echo '<td>'. $row['OwnerName'].'</td>';
    echo '<td>'. $row['Description'].'</td>';
    echo '<td><input type="button" value = "View" onclick="approval()"></td>';
    echo '</tr> ';
}
?> 

<div class="title">
  Add Asset Approval Form
</div>

<div class="form">
   <div class="inputfield">
      <label>Category</label>
      <input type="text" class="input" name="Category">
   </div>  
     
   <div class="inputfield">
      <label>Serial Number</label>
      <input type="text" class="input" name="SN">
   </div>  

  <div class="inputfield">
      <label>Model Name</label>
      <input type="text" class="input" name="Model Name">
   </div> 

   <div class="inputfield">
      <label>Owner ID</label>
      <input type="text" class="input" name="OID">
   </div> 

   <div class="inputfield">
      <label>Owner Name</label>
      <input type="text" class="input" name="OName">
   </div> 

  <div class="inputfield">
      <label>Description</label>
      <input type="text" class="input" name="Desc">
   </div> 

Asset Approval List is a table with lots of row of data and a button, after clicking the button, it will link to Asset Approval Form. I would like to fetch the data from the same row in Asset Approval List to my Asset Approval Form. The data in the table of Asset Approval List is fetched from mysql phpmyadmin. Any idea how to link the same data to Asset Approval Form?

This is my Asset Approval List This is my Asset Approval List

This is my Asset Approval Form

This is my Asset Approval Form

Advertisement

Answer

Assuming there’s a unique ID column in the table, you should include that in the call to approval():

    echo '<td><input type="button" value = "View" onclick="approval('' . $row['SerialNumber'] . '')"></td>';

Then change approval() to include the ID in the URL.

    function approval(serial){
      window.location.href = "AddAssetApproval.php?serial=" + serial;
    }

And AddAssetApproval.php should use $_GET['serial'] to display the appropriate approval form for that serial number.

$stmt = $conn->prepare("SELECT * FROM waiting_approval WHERE SerialNumber = ?");
$stmt->bind_param("i", $_GET['serial']);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement