Hey guys

my question is related to sort table

This is the code for the table:

PHP Code:
$result $conn->query("SELECT query, link, pro,pro_update,ana,ana_update,cell,cell_update,cellother,cellother_update,gen,gen_update,genother,genother_update,author,author_update,other,other_update,date,id
FROM mailing_list
WHERE email = '
$email'
ORDER BY 
$order LIMIT $start_row$max_per_page;");

echo 
"<table class=\"sortable\" id=\"query_quick2\" width=\"100%\" >\r\n";
echo 
"\t<tr><th class=\"sorttable_alpha\" >Updated Query</th><th width=\"10\" class=\"sorttable_alpha\" >Link</th>
<th class=\"sorttable_alpha\" >Promoter Locus</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Anatomical Area</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Cell Type</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Other Cell Type</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Genetic Background</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Other Gen. Back.</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Author</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_alpha\" >Other</th><th class=\"sorttable_alpha\" >Update</th>
<th class=\"sorttable_mmdd\" >Date</th><th class=\"sorttable_nosort\" ></th><th class=\"sorttable_nosort\" ></th>\r\n"
;

if(
$result->num_rows){
while (
$row $result->fetch_array()){
$RowCount ++;
$row_color = ($RowCount 2) ? $color1 $color2;
echo 
"<form method = \"post\" action=\"{$_SERVER['PHP_SELF']}\">";
echo 
"\t<tr id=\"{$row['id']}\" class=\"$row_color\" >
<td>
{$row['query']}</td><td>{$row['link']}</td>
<td>
{$row['pro']}</td><td>{$row['pro_update']}</td><td>{$row['ana']}</td>
<td>
{$row['ana_update']}</td><td>{$row['cell']}</td><td>{$row['cell_update']}</td><td>{$row['cellother']}</td>
<td>
{$row['cellother_update']}</td><td>{$row['gen']}</td><td>{$row['gen_update']}</td><td>{$row['genother']}</td>
<td>
{$row['genother_update']}</td><td>{$row['author']}</td><td>{$row['author_update']}</td><td>{$row['other']}</td><td>{$row['other_update']}</td>
<td>
{$row['date']}</td>
<td><input type=\"submit\" name=\"edit_mail\" value = \"Edit\"/></td>
<td><input type =\"hidden\" name = \"id\" value=\"
{$row['id']}\"/></td>
<td><input type=\"submit\" name=\"delete_mail\" value =\"Delete\"/></td>
</tr>"
;
echo 
"</form>";


}
}

echo 
"</table>"

This is an excerpt of the script which deletes the specific entry:

PHP Code:
} elseif(isset($_SESSION['user_id']) AND isset($_POST['delete_mail'])){
//user is deleting existing queries
$connect=db_connect_2();
$id mysqli_real_escape_string($connect$_POST['id']);


$sql2 "DELETE FROM mailing_list WHERE id='$id'";
$result mysqli_query($connect$sql2) or mysqli_error($conn);

$msgs[] = "Queries DELETED successfully.";
$body "account.php";


I can delete the specific entry like usual at the beginning

but right AFTER i sort the table by clicking a column heading, say, promoter locus, (using sortable.js)

and then when i try to delete a specific entry, problem arises.

Instead of deleting the entry i want, it always deletes the LAST entry.

Now as you can see, i select a specific value for $id, using post method from a form

But shouldn't the value of $id point to the entry i want to delete when i click the "delete" button near it? (i mean it works fine before i sort the table)

Any help would be greatly appreciated

Thanks.