Handling multiple automatically generated buttons? 10-04-2013, 02:35 AM
#1
Sup folks?
I've got a script that generates lots of buttons in a loop. We currently look like this.
![[Image: mAjKJQ2.png]](http://i.imgur.com/mAjKJQ2.png)
The buttons are generated using the following code (everything's being read from a database).
Simplified version:
I left some of the formatting shit out but you get the point. Each button generated is called (for example) 'edit_post_7' or 'edit_post_8'.
The problem is, I want to make ALL these buttons do a very similar thing (e.g. run a function). But I don't want to have to do this for each of them.
I can't do this because there could be thousands of buttons.
What's the best way to handle these events?
I've got a script that generates lots of buttons in a loop. We currently look like this.
![[Image: mAjKJQ2.png]](http://i.imgur.com/mAjKJQ2.png)
The buttons are generated using the following code (everything's being read from a database).
Simplified version:
PHP Code:
<?php while($rows = mysql_fetch_array($query)):
assign variables and output other shit here
echo "<td>" . "<center><input type='submit' value='Edit' name='edit_post_" . $post_id . "'></center>" . "</td>";
endwhile;
?>I left some of the formatting shit out but you get the point. Each button generated is called (for example) 'edit_post_7' or 'edit_post_8'.
The problem is, I want to make ALL these buttons do a very similar thing (e.g. run a function). But I don't want to have to do this for each of them.
PHP Code:
if(isset($_POST['edit_post_7'])){
do my shit
}
if(isset($_POST['edit_post_8'])){
do essentially the same shit
}
I can't do this because there could be thousands of buttons.
What's the best way to handle these events?





![[+]](https://sinister.li/images/modern/collapse_collapsed.png)