Php 如何使用fetch_assoc从数据库和数组创建无序列表
通过从数据库中选择booking引用,将它们排序到一个数组中,然后将每个数组值传递到列表中的每个项目,尝试创建一个列表。e、 g.第一个项目的第一次预订参考,第二个项目的第二次参考等。。。 这是代码Php 如何使用fetch_assoc从数据库和数组创建无序列表,php,database,list,mysqli,unordered,Php,Database,List,Mysqli,Unordered,通过从数据库中选择booking引用,将它们排序到一个数组中,然后将每个数组值传递到列表中的每个项目,尝试创建一个列表。e、 g.第一个项目的第一次预订参考,第二个项目的第二次参考等。。。 这是代码 <html> <head> <title>Manage booking</title> <link rel="stylesheet" type="text/css" href="style1.css"> </h
<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>
管理预订
奥德比格兰维尔网球俱乐部管理预订
您的第一个while($row=$result->fetch_assoc()){..}
将所有内容转移到$bookingArray
中,直到结果集用完。使用第二个while($row=$result->fetch_assoc()){..}
您不会得到更多。此外,您对printf的使用也很奇怪。
尝试以下方法,而不是第二个循环:
foreach($bookingArray as $Booking)
{
echo "<li><a href='UpdateBooking.php'>Booking ID:$Booking</a></li><br>";
}
忽略表前的代码,这只是我的参考。谢谢你的工作。如何将单击列表中项目的$booking附加到URL,以便下一页使用它?
foreach($bookingArray as $Booking)
{
echo "<li><a href='UpdateBooking.php?BookingId=" . urlencode($Booking) . "'>Booking ID:$Booking</a></li><br>";
}