Reputation: 47
I have a MySQL table that is displayed in the webpage and every row has a submit button. When the submit button for a particular row is clicked, the first element i.e. row id should be retrieved. Should I use arrays to store the data or can I obtain the row id from the table I've echoed on screen. Here's the code:
echo "<table>";
while($row = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td align='center' name='bus_id'>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "<td><form name='f1' method='post' action='schedule_list.php'>
<input type='submit' name='book' value='Book'></form></td>";
echo "</tr>";
}
echo "</table";
Upvotes: 0
Views: 51
Reputation: 1737
Use a a button with type submit to submit the ID as follows (and still display a meaningful button title
echo "<td><form name='f1' method='post' action='schedule_list.php'>
<button type='submit' name='book' value='".$row[0]."'>Book</button></form></td>";
Upvotes: 1