I'm currently very stuck on this. I have a table that generates new rows as it loops through a datatable with a while loop. Within the while loop, i have some submit buttons that get re-created on each new row. My goal is to be able to individually control each row separately but I don't know how to accomplish this. So far, i have used a hidden to input the primary key of "id". After searching this site, i found a useful answer that showed me how to post the hidden id as a get variable and run my query with that. It works fine and updates the things I need it to, but it takes 2 page refreshes to do this. Also i had to remove the submit button and replace with a styled anchor tag to append the get variable to the url onclick. Is there anyway i can just leave my buttons or if not, accomplish the query update with only one page refresh instead of two? I'm updating only one field in the datatable. I tried to look into ajax but that's over my head. I'm open to any solution.
<?php
$con = mysql_connect("localhost","maximus1127","");
$db = mysql_select_db("patients",$con);
$get=mysql_query("SELECT patientName, brand, id FROM orders WHERE onOrder=1 and dispensed = 0");
$get2=mysql_query("SELECT patientName, brand FROM orders WHERE onOrder=0 and dispensed = 0");
if(isset($_GET['deleteId'])) {
include ("connection.php");
$sql = "UPDATE `orders` SET dispensed = 2 WHERE id = '".($_GET['deleteId'])."' LIMIT 1";
mysqli_query($link, $sql);
}
?>
<?php include ("header.php"); ?>
<table class="table">
<thead class="thead-inverse">
<h3>On Order</h3>
<tr>
<th>Patient Name</th>
<th>Brand</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<td scope="row"><?php while ($row = mysql_fetch_array($get)) {
//output a row here
echo "<form> <tr><td>".($row['patientName'])."</td> <td>".($row['brand'])."</td><td class='hide'>".($row['id'])."</td><td><div class='btn-group-sm' role='group' aria-label='Basic example'>
<a href='?deleteId=$row[id]' class='btn btn-danger' onclick= 'pageRefresh();'>Cancel</a>
<input type='submit' class='btn btn-primary' name = 'view' value='View'>
<input type='submit' class='btn btn-success' name = 'received' value='Received'>
</div> </td></form>" ;
}?>
</td>
</tr>
</td>
</tr>
</tbody>
</table>
<table class="table">
<thead class="thead-default">
<h3>Received</h3>
<tr>
<th>Patient Name</th>
<th>Brand</th>
<th>Notified</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row"><?php while ($row = mysql_fetch_array($get2)) {
//output a row here
echo "<form><tr><td>".($row['patientName'])."</td><td>".($row['brand'])."</td><td></td>
<td> <input type='submit' class=' btn btn-success' value='Dispense' /></td></form>";
}?>
</tr>
</tbody>
</table>
<?php include("footer.php"); ?>