Jump to content


how to delete a row in mysql.


1 reply to this topic

#1 Macintosh

    Young Padawan

  • Members
  • Pip
  • 28 posts

Posted 28 November 2006 - 02:05 PM

Im using the following code, for very simple work.. it simply gets and print the comments which are stored in the database.
Now it will show like
comment 1.
comment 2.
comment 3. etc etc

i want to add 'delete' option that i can delete any comment.
it displays like

comment 1. Delete
comment 2. Delete
comment 3. Delete
So that when i click on delete, it simply deletes the comment and print the remaining comments.
Its very simple. i hope you understand.

Quote

$result = mysql_query("select * from comments order by id desc limit 10");
//the while loop
while($r=mysql_fetch_array($result))
{
//getting each variable from the table

echo $r["comment"];
echo "<br />";

}


#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 28 November 2006 - 02:11 PM

if (isset($_GET['delete'])) {
$delete = mysql_query("DELETE FROM `comments` WHERE `id` = '".mysql_real_escape_string($_GET['delete'])."'") OR die(mysql_error());
if ($delete) {
echo 'Deleted';
} else {
echo 'Could not be removed';
}

$result = mysql_query("select * from comments order by id desc limit 10");
//the while loop
while($r=mysql_fetch_array($result))
{
//getting each variable from the table

echo $r["comment"].' :: <a href="'.$_SERVER['PHP_SELF'].'?delete='.$r['id'];
echo "<br />";

}

Should be what you are looking for =)

Matt





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users