Pulling extra fields for dynamic checkbox form

Hello,

Here is the situation:

we have three tables-

1.“Event” Table
2. “Event_statuses” Table
3.“Status” Table

The “Event” table holds basic information about an event:
id, location, date, time.

The “Event_statuses” table holds

id, date, event_id, status_id

The “Status” table holds:
id, statusname

I am dynamically generating the list of events with a checkbox next to each and a date field. so an event can be checked and a date entered to show the date it was activated.

I have got the list of events to show and the ones that are selected for the event being viewed but am struggling to get the date to show.

any help with this would be very much appreciated…

Code being used is as follows:

Controller file:

$eventid = mysqli_real_escape_string($link, $_SESSION['eventid']);

// Get list of statuses assigned to this event

$sql = "SELECT statusid, date FROM Event_statuses WHERE event_id='$event_id'";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching list of assigned statuses.';
	include 'error.php';
	exit();
}


while ($row = mysqli_fetch_array($result))
{
	$selectedstatuses[] = $row['statusid'];
	$date = $row['date'];
}

// Build the list of all statuses

$sql = "SELECT id, statusname FROM Status";
$result = mysqli_query($link, $sql);
if (!$result)
{
	$error = 'Error fetching list of statuses.';
	include 'error.php';
	exit();
}

while ($row = mysqli_fetch_array($result))
{
	$statuses[] = array(
			'id' => $row['id'],
			'statusname' => $row['statusname'],
			'selected' => in_array($row['id'], $selectedstatuses),
			'date' => $date);
}

include 'form.php';
exit();

The Form being populated

			<fieldset>
			<legend>Statuses</legend>
			<?php for ($i = 0; $i < count($statuses); $i++): ?>
				<div>
				
					<label for="statuses<?php echo $i; ?>"><input type="checkbox" name="statuses[]" id="statuses<?php echo $i; ?>"
						value="<?php htmlout($statuses[$i]['id']); ?>"
						<?php if ($statuses[$i]['selected']) {echo ' checked="checked"';}?>>
							<?php htmlout($statuses[$i]['id']); ?></label>:
						<?php htmlout($statuses[$i]['statusname']); ?>
						<label for="Date">Date</label> <input type="text" name="date" id="date" value="<?php htmlout($statuses[$i]['date']); ?>" >	
						
				</div>
			<?php endfor; ?>
		</fieldset>