<?php
if (isset($_GET['flyerID']))
$FlyerID = $_GET['flyerID'];
$DBConnect = @mysqli_connect("host", "UN", "pword")
Or die("<p>Unable to connect to the datbase server.</p>" . "<p>Error Code ".mysqli_connect_errno().": ".mysqli_connect_error()) . "</p>";
$DBName = "agentsleuthdb";
@mysqli_select_db($DBConnect, $DBName)
Or die("<p>Unable to select the database.</p>" . "<p>Error Code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) ."</p>";
$TableName = "FEEDBACK";
$SQLstring = "SELECT * FROM $TableName order by FIRSTNAME";
$QueryResult = @mysqli_query ($DBConnect, $SQLstring)
Or die("<p> Unable to exequte Select query.</p>"."<p>Error Code ".mysqli_errno($DBConnect) .": ".mysqli_error
($DBConnect))."</p>";
if (mysqli_num_rows($QueryResult) == 0){
exit("<p>There is no feedback</p>");
}
?>
<table border="1">
<tr>
<th width = "15%">First Name </th>
<th width = "15%">Last Name </th>
<th width = "15%">Email Addr </th>
<th width = "15%">Company </th>
<th width = "40%">Feedback </th>
</tr>
<?php
$Row = mysqli_fetch_row($QueryResult);
do {
echo "<tr><td>{$Row[0]}</td>";
echo "<td>{$Row[1]}</td>";
echo "<td>{$Row[2]}</td>";
echo "<td>{$Row[3]}</td>";
echo "<td>{$Row[4]}</td></tr>";
$Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
mysqli_free_result($QueryResult);
mysqli_close($DBConnect);
?>
它只返回一行..如何返回所有条目?
答案 0 :(得分:3)
你试过吗
while ($Row = mysqli_fetch_row($QueryResult))
说明here
或
while ($Row = mysqli_fetch_array($QueryResult, MYSQL_ASSOC))
说明here
希望这有帮助。
答案 1 :(得分:0)
在您的代码中,只有您第一次调用mysqli_fetch_row
时才会生成$Row
索引数组。
这就是您在使用索引($Row
,$Row[0]
等)访问$Row[1]
内容时看到输出的原因。
之后,您在关联数组中转换mysqli_fetch_assoc
的{{1}},因此使用输出索引访问$Row
不再有效。
将$Row
循环替换为建议的第一个do ... while
循环。