0

I am writing a sort of custom Administrative UI.

I have implemented the php code that inserts and reads records from the DB table.

The records are visualized in a table in the UI in the below pattern:

test title

Added: 2011-12-29 17:34:35

test2

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test title

Added: 2011-12-29 17:34:35 tests

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

test title2 Added: 2011-12-29 17:34:35 test22

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have the following structure for my database table:

TABLE news ( guid , lang , title , content , date, PRIMARY KEY (guid, lang) )

guid is generated with php com_create_guid () function.

How can I implement buttons Edit and Delete beside each item?

Thanks a lot!

1 Answer 1

2
  • you can make a form with hidden inputs that contain record id and buttons with different names. For each record:
<form action="action.php" method="POST">
   <input type="hidden" name="record_id" value="12">
   <input type="submit" value="Edit" name="doedit">
   <input type="submit" value="Delete" name="dodelete">
</form>

In action.php:

if (isset($_POST['doedit'])){do smth.}
if (isset($_POST['dodelete'])){do smth.}
  • you can make links instead giving each different url containing action and record id as GET parameters.
    Suppose you have a file action.php. For record number 12 the "edit" link will go to "action.php?do=edit&record=12", the "delete" link will go to "action.php?do=delete&record=12".
    In action.php:

    $do=$_GET['do']; //you should add some validation of $_GET
    $rec=$_GET['record']; if ($do=='edit'){do smth.} if ($do=='delete'){do smth.}

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer, could you please elaborate a little bit on each option? I am failry new to web development.
Hi, thanks a lot! I have implemented the first option. For record_id i am passing the unique guid for each record from the db table. Now I am wondering how to actually edit the text of each record... After the "Edit" button is pressed how I can make the text in each record editable?
You can output a form with editable textfield and the record as the text inside in the action.php. you can change the div with the record to textfield using javascript. I think there are plenty other options
I have actually implemented it a bit differently - using radio buttons, as they support the same name but different values, and allow the editing of one single record at a time. On $_POST I read only the value of the selected radio button, and after that handle the database query based on this id. I also implemented everything in one file where the action = "" to avoid passing parameters to another php file. WORKS. Thanks for the basic idea! Was of great help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.