我正在運行一個相當直接的mysql請求並將結果返回給一個表。數據庫中有三條記錄,查詢從兩個表中提取。因此,我得到了三條記錄(回顯mysql_num_rows)的計數,但只有兩條顯示在表中。在數組結果上使用print_r命令只顯示一個特定的記錄 - 其他記錄顯示在print-r中..我向db添加了另一條記錄,現在有三條記錄顯示 - 並且與以前相同的記錄不顯示和是print_r命令中的唯一記錄。 下面是相關代碼:PHP mysql_fetch_array沒有返回所有行 - 一行總是被忽略
<td id="page1">
<?php
$limit = 15; // Set limit to show for pagination
$page = $_GET['page']; // get page number from submit
if($page)
$start = ($page - 1) * $limit; // first item to display on this page
else
$start = 0; // if no page var is given, set start to 0
$query = "SELECT PartyMstr.PartyMstrID, UserName, FirstName, LastName, XrefPartyRoleID
FROM PartyMstrRole, PartyMstr
WHERE PartyMstr.PartyMstrID = PartyMstrRole.PartyMstrID &&
PartyMstrRole.XrefPartyRoleID = 1
ORDER BY LastName, FirstName ASC
LIMIT $start, $limit
";
$result = mysql_query($query, $connection);
$row = mysql_fetch_array($result) or die(mysql_error());
$totalitems1 = mysql_num_rows($result);
?>
<center><h3> Admin User List </h3></center>
<?php
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>PartyMaster ID</th>";
echo "<th>UserName</th>";
echo "<th>Last, First</th>";
echo "<th>Link</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['PartyMstrID'];
echo "<td>";
echo $row['UserName'];
echo "<td>";
echo " " . $row['LastName'] . ", " . $row['FirstName'] . " ";
echo "<td>";
echo "<a href = \"http://www.505575.com/editUser.php?id=" . $row['PartyMstrID'] . "\" >Edit</a>";
// echo "<td>";
// echo $row['XrefPartyRoleID'];
echo "</td></tr>";
}
echo "</table><br/><br/> ";
$paginaton = getPaginationString($page, $totalitems, $limit,
$adjacents = 1,
$targetpage = "adminUserList.php",
$pagestring = "?page="
); // Functon found in functions.php
echo $paginaton;
?>
</td>
我花了很多時間在網上尋找沒有成功的解釋。我已經關閉了$pagination
代碼行,但沒有任何效果。我嘗試了各種其他技巧和迴應輸出。返回的行數(n
)始終正確,但只有n-1
行出現在表中。那裏有任何想法?
謝謝 - 唐
作爲一個澄清:你堅持'print_r($ row)'在你的'while循環中嗎? –
你可能會考慮學習'PDO',這將被棄用。 – 2011-10-11 03:41:26