Jump to content

Insert Data From Generated Table?


euel

Recommended Posts

Hi guys,

Im making an event booking/reservation site,

I have 5 tables (Malls, Events, Booking, Reservation and Users) which are all connected and doing fine.

I created a function which is this...

function select_all_events_by_mall_id($mall_id)
{

echo "<table id='event_table'>";
echo "<th>Event Name</th>";
echo "<th>Event Location</th>";
echo "<th>Number of Cars</th>";
echo "<th>Description</th>";
echo "<th>Booked</th>";
echo "<th>Reserved</th>";
echo "<th>Reserved Until</th>";
echo "<th>Vacant</th>";
$events_set = select_all_events($mall_id);


	while($events = mysql_fetch_array($events_set))
	{
		echo "<tr>";
		echo "<td>" . $events['event_name'] . "</td>";
		echo "<td>" . $events['event_location'] . "</td>";
		echo "<td>" . $events['number_of_cars'] . "</td>";
		echo "<td>" . $events['description'] . "</td>";
			// Booked
			echo "<td>";
					$booked_set = select_all_booking($events['id']);

					while($booked = mysql_fetch_array($booked_set))
					{

						$user_set = select_all_user_booked($booked['users_id']);
						while($user = mysql_fetch_array($user_set))
						{
						echo $user['company'] . ", " . $user['branch'] . "<br />";
						}
					}

			echo "</td>";

			// Reserved
			echo "<td>";
				echo "<ol>";
					$reserved_set = select_all_reservation($events['id']);
					while($reserved = mysql_fetch_array($reserved_set))
					{
					if(empty($reserved['events_id']))
							{
								echo "No Reservation's ";
							}
					else
						{


							$reserved_user = select_all_user_reserved($reserved['users_id']);
							while($user_set = mysql_fetch_array($reserved_user))
							{

								echo "<li>" . $user_set['brand'] . ", " . $user_set['branch'] . "</li>";

							}

						}
					}
					echo "</ol>";
			echo "</td>";

			// Expiration Date
			echo "<td>";
				echo "<ol>";
				$reserved_set = select_all_reservation($events['id']);
					while($reserved = mysql_fetch_array($reserved_set))
					{

							$reserved_user = select_all_user_reserved($reserved['users_id']);
							while($user_set = mysql_fetch_array($reserved_user))
							{

								$exp_date = select_all_expiration_date($user_set['id']);
								while($date = mysql_fetch_array($exp_date))
								{
									echo "<li>" . $date['expiration_date'] . "</li>";
								}
							}


					}
				echo "</ol>";
			echo "</td>";

			//Vacant
			echo "<td>";
					$vacant_set = select_all_booking($events['id']);
					$booking_count = mysql_num_rows($vacant_set);
					$reserved_count = mysql_num_rows($reserved_set);
					$total_count = $booking_count + $reserved_count;
					$vacant = $events['number_of_cars'] - $total_count;
					if($vacant < 0)
					{
						echo "This Event is fully booked";
					}
					else
					{
						echo $vacant;
					}
			echo"</td>";


		echo "</tr>";
	}
echo "</table>";


}

The function starts by receiving an id from picking a mall name from a select tag.

It works fine, it outputs the data on the page like i want it to, but my problem is that i need a way to

add a submit or any button to each generated row that will, when clicked will insert the event id and user id (who clicked it) to my booking/reservation table as a new row.

I tried adding a form inside my function and saving the event id every loop but when i click the submit button i think it doesn't work (or i made a mistake)..

Sorry if my coding sucks, I'm kinda new in php.

Sorry if its kinda confusing my head is spinning right now from thinking this stuff the whole day..

Thanks in advance for any comments and ideas.

 

Link to comment
https://forums.phpfreaks.com/topic/252191-insert-data-from-generated-table/
Share on other sites

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.