0
<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

2
  • Is there a unique ID column in the table? Commented Jan 21, 2021 at 5:13
  • yeap Serial Number is my unique ID Commented Jan 21, 2021 at 5:54

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

12 Comments

may i know where to put $_GET['serial'] at?
Use it when you're looking up the record to approve.
I've added all of those but when i clicked on the button I get this error -> Uncaught ReferenceError: LPA101121104552 is not defined onclick @ C:\xampp\htdocs\hallbar23\hallbar\AssetApprovalList.php:105:191
I mistakenly used PHP . instead of JS + for concatenation in the approval() function.
owhhhhh so what should i do to achieve the solution?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.