How to get id of selected table element in php
I have to get id
from the table to make a query. But I did it this way.
My table: Id (AI), name (Varchar); authir (VARCHAR), category (VARCHAR);
I think if there are any solutions to thank you, my problem appears on the following lines:
Print "<td><a href='editt.php?id=$id'>edit</a> </td>";
Print "<td> <a href='delete.php?id=$id'>delete</a> </td>";
Complete code:
<table class="table table-hover">
<thead>
<tr>
<th>Book name</th>
<th>Author</th>
<th>Category</th>
<th><th>
<th><th>
</tr>
</thead>
<tbody>
<?php
$id = 0;
while($info = mysql_fetch_array($data)) {
$id++;
Print "<tr>";
Print" <td>".$info['name']."</td>";
Print "<td>".$info['author']."</td>";
Print "<td>".$info['category']."</td>";
Print "<td> <a href='editt.php?id=$id'>edit</a> </td>";
Print "<td> <a href='delete.php?id=$id'>delete</a> </td>";
Print " </tr>";
}
?>
I was wondering if there are other ways to do a redirect with the current selected row id = $ id Can you see the photo there if the pointer is in editing or removing the link link id = 2, but in fact in the db it is 3
source to share
if you can show the table structure and the complete php code we can help more, but for now it seems like you just need to:
while($info = mysql_fetch_array($data)) {
Print "<tr>";
Print" <td>".$info['name']."</td>";
Print "<td>".$info['author']."</td>";
Print "<td>".$info['category']."</td>";
Print "<td> <a href='editt.php?id=".$info['id']."'>edit</a> </td>";
Print "<td> <a href='delete.php?id=".$info['id']."'>delete</a> </td>";
Print " </tr>";
}
And stop using functions mysql_*
, it is deprecated. You have to use mysqli or PDO.
source to share