Login Register






Handling multiple automatically generated buttons? filter_list
Author
Message
Handling multiple automatically generated buttons? #1
Sup folks?

I've got a script that generates lots of buttons in a loop. We currently look like this.

[Image: 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?

Reply

RE: Handling multiple automatically generated buttons? #2
Code:
<?php while ( $rows = mysql_fetch_array ( $query ) ) { echo "<td><center><a href='index.php?edit&id={$post_id}' title='Edit post'>Edit</a></center></td>" } ?>

Then to process it:
Code:
<?php if ( isset ( $_REQUEST['edit'] ) ) { if ( isset ( $_REQUEST['id'] ) && is_numeric ( $_REQUEST['id'] ) ) { // do shit here with $_REQUEST['id'] instead of $_POST['edit_post_#'] } } ?>

This is a very basic and insecure way of doing it, but it should get your job done... Hope this is what you are looking for..

Reply

RE: Handling multiple automatically generated buttons? #3
Brilliant. Thank you!

Reply

RE: Handling multiple automatically generated buttons? #4
I was about to answer this for you, anyway Polar answered.
  • Contact Paradox or Uzi for Admin related duties
  • Contact Operate for Staff queries
  • PM me if you need any help.

Reply