Forum Moderators: coopster

Message Too Old, No Replies

Two buttons to Edit or Delete

Either button would affect a particular row

         

neophyte

2:39 am on Aug 20, 2004 (gmt 0)

10+ Year Member



Hello everyone! This question basically involves streamlining an admin interface for a web site.

Here's the issue: I'm pulling a table of information into a page via php. Each row contains a headline, body text and author.

Next to each row, the boss wants a REGULAR button that says Edit, and then another REGULAR button that says Delete.

I'm succesful at passing the correct row id using single radio button beside each row with a Delete (submit) or Edit (submit) button at the bottom of the page.

But, the boss don't want that. He wants each row to have two regular buttons beside each row.

Of course, if I set the value of these regular buttons to my row id, the buttons display the row id rather than "Delete" or "Edit" as required.

So...does anyone know of a way to keep the Delete or Edit label of these two buttons which, when pressed, would pass the correct value of the row they are adjescent (sp?) to?

I've thought about using hidden fields which would contain the row id numbers, but am not sure how to reference them once either of the two buttons were pressed.

Any and all help greatly appreciated.

Neophyte

willybfriendly

2:53 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put the buttons in their own form element and have it call the right script, i.e action="edit.php" and action="delete.php"

Wrap it all up in a table so it looks nice for your boss. Give me a little bit of the raise that you get when you explain what a difficult technical problem you were able to solve :)

WBF

Birdman

2:54 am on Aug 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello and welcome to webamsterworld.com!

Bosses can really be a pain, huh? Not to worry, there is a solution.

Use the name attribute of the submit buttons to determine what was clicked.

Example

<input type="submit" name="edit_1032" value="edit" />
<input type="submit" name="delete_1032" value="delete" />

In your PHP script...

foreach($_POST as $key => $val){

if ($val == "edit"){
$arr = explode("_", $key);
$id = $arr[1]; // THIS IS YOUR ITEM TO DEAL WITH(1032 in this case)
...add edit code here...
}

if ($val == "delete"){
$arr = explode("_", $key);
$id = $arr[1]; // THIS IS YOUR ITEM TO DEAL WITH(1032 in this case)
...add delete code here...
}

}

Hope that helps out...

neophyte

2:27 am on Aug 21, 2004 (gmt 0)

10+ Year Member



willybfriendly and Birdman:

Thanks so much for your assistance - Birdman's recommondation of splitting the value of each button into the button name and row value ... and then using the explode() function ... worked like a charm!

Of course, my boss isn't impressed (he's never impressed); his only response was "yeah, that's what I mean ... why didn't you get that done a week ago?"

Such is life.

Neophyte

willybfriendly

4:43 am on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No bonus :(

I thought Birdman's solution was more elegant too, by the way.

WBF