Trying to create a list by selecting booking references from the database, sorting them into an array and then having each array value passed into each item on the list. e.g. first booking reference on the first item, second reference on the second item etc... Here is the code.
<html>
<head>
<title>Manage booking</title>
<link rel="stylesheet" type="text/css" href="style1.css">
</head>
<body>
<h3>Oadby Granville Tennis Club Manage Booking</h3>
<br><br><br>
<?php
include "dbconnect.php";
session_start();
$login_ID = $_SESSION['id'];
$query = "SELECT Booking_ID
FROM `booking`
WHERE Login_ID = '$login_ID';";
$bookingArray = array();
$result = $mysqli -> query($query);
while ($row = $result->fetch_assoc()){
printf ("%s<br>", $reference = $row["Booking_ID"]);
array_push($bookingArray, $reference . "<br>");
}
print_r ($bookingArray);
?>
<table border="1" style="width:50%">
<caption>Please select a booking to edit:</caption>
<tr>
<td>
<ul style="list-style-type:circle">
<?php
$arrayNo = 1;
while ($row = $result->fetch_assoc()){
printf ("<li><a href='UpdateBooking.php'>Booking ID:%s</a>" . $bookingArray[$arrayNo] . "</li><br>");
$arrayNo = $arrayNo + 1;
}
?>
<li><a href="UpdateBooking.php">Booking ID</a></li>
</ul>
</td>
</tr>
</body>
</html>
Your first while ($row = $result->fetch_assoc()) {..}
transfers everything into $bookingArray
until the result set is exhausted. With your second while ($row = $result->fetch_assoc()) {..}
you don't get anything more. Additionally, your use of printf is weired.
Try this instead your second loop:
foreach($bookingArray as $Booking)
{
echo "<li><a href='UpdateBooking.php'>Booking ID:$Booking</a></li><br>";
}
However, UpdateBooking.php
wont know which booking should be changed. So you should consider to append the BookingId to the URL.
Edit 2016-03-02: To append the BookingId to the URL you should try:
foreach($bookingArray as $Booking)
{
echo "<li><a href='UpdateBooking.php?BookingId=" . urlencode($Booking) . "'>Booking ID:$Booking</a></li><br>";
}