Oblivion Oblivion - 5 months ago 23
PHP Question

PHP loop which creates X buttons

I'm creating an banner management tool which uses an SQL database to store its data once added. there is a tab which shows for every banner in this database an update and delete button. These buttons are created in a PHP based loop so i will have X amount of update and delete buttons.

Now depending on which button i press i will go to an update vieuw of the the item wherunder the update button was clicked.

The problem i encounter since these buttons all have the same name is that i can't distinguish which button has been pushed. Every item in the DB has en ROWID, however i can't figure out how to get the ID once u push the button...

Here is the code of how these buttons are generated.

do {
$entry = $dbase->querySingle("SELECT name FROM banners where ROWID='$currentRowNumber'");

echo "<tr>";
echo "<td width=\"50\">". $entry ."</td>";
echo "</tr>";

echo "<tr>";
echo "<td><input type=\"submit\" name=\"operation\" value=\"Update\"></td>";
echo "<td><input type=\"submit\" name=\"operation\" value=\"Delete\"></td>";
echo "</tr>";

$currentRowNumber++;

} while ($dbase->querySingle("SELECT name FROM banners where ROWID='$currentRowNumber'") != NULL);


I was wondering if anyone has any idea on how to distinguish these buttons.
Maybe a hidden factor that i can read out below? (don't know if such a thing exists)

Regards

Answer

You could wrap all operations per row in a form that has an input type="hidden" value="$id" containing the ID of the item, or use an action="/update?id=$id" per form, or, if you want to stick to one large form, you could use name="update[$id]" for the submit button.