使用 PHP 返回行的问题
<?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);
?>
它只返回一行..我怎样才能返回所有条目?
<?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);
?>
It only returns one row.. how can I return all entries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过
描述此处
或
描述这里
希望这会有所帮助。
Have you tried
Description here
or
Description here
Hope this helps.
在您的代码中,仅在您第一次调用
mysqli_fetch_row
时,这会使$Row
成为索引数组。这就是为什么当您使用索引访问
$Row
的内容时会看到输出 ($Row[0]
,$Row[1]
, ETC..)。之后,您
mysqli_fetch_assoc
将$Row
转换为关联数组,因此使用输出索引访问$Row
不再起作用。将您的
do ... while
循环替换为 forloney 建议的第一个while
循环。In your code, only the first time you call
mysqli_fetch_row
, which makes an$Row
an indexed array.This is why you see output when you access the content of
$Row
with an index ($Row[0]
,$Row[1]
, etc..).Afterwards, you
mysqli_fetch_assoc
which turns$Row
in an associative array, thus accessing$Row
with an index for your output doesn't work anymore.Replace your
do ... while
loop by the firstwhile
loop aforloney suggested.