mysql - Individual row controls populating table with while loop in PHP -


i'm stuck on this. have table generates new rows loops through datatable while loop. within while loop, have submit buttons re-created on each new row. goal able individually control each row separately don't know how accomplish this. far, have used hidden input primary key of "id". after searching site, found useful answer showed me how post hidden id variable , run query that. works fine , updates things need to, takes 2 page refreshes this. had remove submit button , replace styled anchor tag append variable url onclick. there anyway can leave buttons or if not, accomplish query update 1 page refresh instead of two? i'm updating 1 field in datatable. tried ajax that's on head. i'm open solution.

<?php $con = mysql_connect("localhost","maximus1127",""); $db = mysql_select_db("patients",$con); $get=mysql_query("select patientname, brand, id orders onorder=1 , dispensed = 0"); $get2=mysql_query("select patientname, brand orders onorder=0 , dispensed = 0");  if(isset($_get['deleteid'])) {      include ("connection.php");    $sql =  "update `orders` set dispensed = 2 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 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 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"); ?> 

first of all, should fix html. have shown not valid html. cannot have <tr> inside of <td>... also, shouldn't need have form each row, have 1 form buttons. form append value of button used submit it, use advantage.

<tbody>     <?php          while ($row = mysql_fetch_array($get2)) {             //output row here             echo "<tr><td>".($row['patientname'])."</td><td>".($row['brand'])."</td><td></td>";             echo "<td><button type='submit' class='btn btn-success' name='dispense_id' value='".$row['id']."' />dispense</button></td>";         }     ?> </tbody> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -