我试图让 while 循环显示从表中选择的所有记录,并迭代封装在 <div> 中的结果。我的查询正在工作,而 while 正在显示一些东西……但只有最新的记录。我不知道为什么会这样,而且我对 PHP 很陌生,所以任何帮助都会很棒。
代码:
<?php
//Connect to database and select table
$conn = mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("substest", $conn) or die(mysql_error());
//Issue query
$get_features = "SELECT ID, Title, DateReceived, Synopsis FROM features ORDER BY ID";
$r_get_features = mysql_query($get_features) or die(mysql_error);
if(mysql_num_rows($r_get_features) < 1) {
$display_block = "<div class=\"inner\"><h2>Nothing to display</h2></div>";
}
else {
while($feat_array = mysql_fetch_array($r_get_features)) {
$feat_id = $feat_array["ID"];
$feat_title = stripslashes($feat_array["Title"]);
$feat_dater = stripslashes($feat_array["DateReceived"]);
$feat_synopsis = stripslashes($feat_array["Synopsis"]);
$display_block = "<div class=\"inner\">";
$display_block .= "<h2>".$feat_title."</h2>";
$display_block .= "<label for \"id\">ID:</label>";
$display_block .= "<span class=\"formresult\" id=\"id\">".$feat_id."</span><br />";
$display_block .= "<label for=\"title\">Title:</label>";
$display_block .= "<span class=\"formresult\" id=\"title\">".$feat_title."</span><br />";
$display_block .= "<label for=\"datereceived\">Date Received:</label>";
$display_block .= "<span class=\"formresult\" id=\"datereceived\">".$feat_dater."</span><br />";
$display_block .= "<label for=\"synopsis\">Synopsis:</label>";
$display_block .= "<span class=\"formresult\" id=\"synopsis\">".$feat_synopsis."</span><br />";
$display_block .= "</div>";
}
}
?>
<html>
<head>
<title>Galway Film Fleadh - View Submitted Feature Films</title>
<link href="css/submissions.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div class="inner">
<h1>Galway Film Fleadh - View Submitted Films</h1>
</div>
<?php
print $display_block;
?>
</div>
</body>
</html>