hi,
I can displayed data from list/menu from 3 different tables in database in a table and in each row of the table I had a delete button. The problem is I did not know how to delete a single row when i click the button. Anyone can help?
This is how I selected my data into a table.
if(isset($_POST['display']))
{
$tables = array("Blog posts"=>"blog","News"=>"news", "Announcement"=>"announcement");
$orderby = array("Blog posts"=>"blog_id","News"=>"news_id", "Announcement"=>"announ_id");
$category = mysql_real_escape_string($_POST['list']);
$sql = "SELECT * FROM ".$tables[$category]." ORDER BY ".$orderby[$category]." ASC";
$result=mysql_query($sql);
while($nt=mysql_fetch_array($result)){
print ("<table width='780' border='1'>
<tr>
<td width='677'>"); echo "$nt[title] "; print("</td>
<td width='100'>"); echo "$category<br>"; print("</td>
<td width='30'><form name='input' action='display_allposts.php' method='post'>
<input type='submit' name='delete' value='Delete' />
</form> </td>
</tr>
</table>");
}
}
This is my delete function
if(isset($_POST['delete']))
{
$category = mysql_real_escape_string($_POST['list']);
$tables = array("Blog posts"=>"blog","News"=>"news", "Announcement"=>"announcement");
$orderby = array("Blog posts"=>"blog_id","News"=>"news_id", "Announcement"=>"announ_id");
$sql = "DELETE FROM ".$tables[$category]." WHERE ".$orderby[$category]. " = $id";
$result=mysql_query($sql);
}