display data from db..with edit delete butons

Discussion in 'HTML & Website Design' started by ianlufc, Apr 16, 2008.

  1. #1
    Hi Guys

    I am trying to display rows from a mysql table into a html table...getting it to display is not a problem but i want to add to it....
    for every row displayed i want a edit and delete button

    if i could display them into text boxes it would probably be better but im not sure how to do that and then get them interacting with the buttons

    any help appreciated
     
    ianlufc, Apr 16, 2008 IP
  2. ianlufc

    ianlufc Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anyone any views on above
     
    ianlufc, Apr 17, 2008 IP
  3. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well what programming language are you using? I am presuming PHP.

    This is how I would do it,

    First, I am presuming that you are using a while() loop to display each record in your database, If that is the case, i would add a link to a page called edit.php and delete.php to that loop. So that for each row of you rhtml table you have a link to a page called edit.php and delete.php

    Then where you have each link to edit.php add the 'id' of each row to this, like so, edit.php?id=1

    I presume you know how to do that... (also I presume you have an 'id' field in your database.

    Then in the edit.php page us the GET method to get the 'id' of the record to alter. Then run a query to
    
    SELECT * FROM db WHERE (id == $_GET[id])
    
    Code (markup):
    and put the result into an array, (mysql_fetch_array)

    Then create a HTML form with the with the values of the record in the value argument, for example.

    
    <form method="post">
    <input name="age" id="age" value="<?php echo $array[id]; ?>">
    <input type="submit" name="submit" value="Alter">
    </form>
    
    Code (markup):
    Then use something to detect when the submit button has been pressed, like,
    
     if (isset($_POST[submit]))
    {
    SQL HERE
    }
    
    Code (markup):
    Then where I typed SQL here you would use the UPDATE sql syntax.

    Likewise, I would do the same for the delete.php?id=id

    I would then use the DROP sql, (and of course there is no need to create a form in the delete.php)

    I havn't tested any of the above, it is just a simple example.
     
    nicangeli, Apr 17, 2008 IP