Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation How to display rows of data with edit/delete links?

    If I wanted to list a bunch of records in a database through a table, and also have edit/delete links for each record on the side, how would I go about coding something like this? I know I have to use a while or foreach loop to display the records but how to I add the relevant links for each record?

    In context, I am trying to display a list of clients, with edit and delete links which will allow me to edit information for that client or delete the whole client.

    Thanks in advance.

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    PHP Code:
    $qry mysql_query('SELECT * FROM tblClients'):
    while(
    $r=mysql_fetch_array($qry)) {

        echo 
    '<a href="edit.php?client='.$r['client_id'].'">Edit ' $r['client_name'] . '</a> | ';
        echo 
    '<a href="delete.php?client='.$r['client_id'].'">Edit ' $r['client_name'] . '</a>';

    use get to access the client. SELECT * FROM table WHERE clientID = $_GET['client_id']. update/delete as necessary.

  • Users who have thanked met for this post:

    Emkay (11-04-2009)

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    716
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Im doing the exact same thing at the moment!

    Give me like 10 minutes and il give u it.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by met View Post

    use get to access the client. SELECT * FROM table WHERE clientID = $_GET['client_id']. update/delete as necessary.
    Congratulations! You just pwnd his db!

    I understand trying to shoot off a quick answer as I do that myself, but this is a textbook example of how not to write a query. Do him a favor and toss in the mysql_real_escape_string line anyway.
    Are you a Help Vampire?

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks but how do I actually code the functionality of the edit/delete links though? How would it know which to edit or delete once it clicks on the link?

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That portion of met's code is workable. Notice that each link is keyed with the client's unique id from the database.
    Are you a Help Vampire?


  •  

    Posting Permissions

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