Jump to content

Help with dynamically created table with related fields


mlummus

Recommended Posts

I'm trying to create a table form that pulls in "Extra" choices from a table and allows users to select a number of days and number of guests for each choice. I started creating it a a checkbox field but am thinking just using the name as a label and setting days and guests to default "0" might be a better bet. Guidance from someone more experienced with this? Also, how do I store the submission (db structure - in the "reservations" table, another?). I'm new to this and feel kind of lost with this challenge.

 

//Extras
$query = "select * from extras";
$data = mysqli_query($db, $query);
$num = mysqli_num_rows($data);

echo "<p><b>Extras:</b></p>";
for ($i=0; $i<$num; $i++)
{
$row = mysqli_fetch_array($data);
$extra_id = $row['extra_id'];
$extra_name = $row['extra_name'];
$extra_rate = $row['extra_rate'];

echo "<p><input type='checkbox' name='extra_id[]' value = '$extra_id'
/>$extra_name <i>\$$extra_rate</i>  Num Days<input type='text' name='d$extra_id' />  Num Guests<input type='text' name='g$extra_id' />";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.