SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Braveheart4's Avatar
    Join Date
    Nov 2005
    Location
    Macedonia
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Simple delete row, help!

    I have a table with news listed from the database. on the right column I have a delete link. What I want to accomplish is when you click that particular row on the delete link, the row to be deleted.

    I know it's simple, but since I'm a beginner it's still quite complicated for me.

    Here is a screenshot for more detailed explanation:

    list_news.png
    Author at GraphicRiver

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The idea is to pass a unique identifier of a row to the delete link, in such way that you can use it in sql delete query:
    PHP Code:
    //delete.php?id=123

    $sql="delete from t1 where id=".(int)$_GET['id'];

    //... 
    Saul

  3. #3
    SitePoint Addict Braveheart4's Avatar
    Join Date
    Nov 2005
    Location
    Macedonia
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I know that by now, but the problem is how to make it work only when I click the delete link. How to find out that I have clicked on a particular delete link I guess a short function should do it, but how?
    Author at GraphicRiver

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So, hm, I don't think you know it, if you're asking that.

    Your image is still pending so I'm gonna use some basic example. Your data output script may look something like this:
    PHP Code:
    $sql="select * from t1";
    $r=mysql_query($sql);
    while(
    $row=mysql_fetch_array($r)){
      echo 
    "<tr><td>$row[f1]</td><td>$row[f2]</td><td><a href=\"delete.php?id=$row[id]\">Delete</a></td></tr>";

    So you already associate every link with each row by outputting data, thus your delete.php "knows" which row to delete.
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •