Skip to content
PHP Logo

How can data from multiple rows be passed to individual buttons in a PHP form?

To pass data from multiple rows to individual buttons in a PHP form, you can use a loop to iterate through the rows of data and create a button for each row. You can set the value of each button to the corresponding data from the row, allowing you to pass that data when the button is clicked.

php
<?php
// Assuming $data is an array containing the rows of data
foreach ($data as $row) {
    echo '<form method="post" action="process.php">';
    echo '<input type="hidden" name="data_id" value="' . $row['id'] . '">';
    echo '<button type="submit" name="submit">' . $row['name'] . '</button>';
    echo '</form>';
}
?>