我有一個非常基本和簡單的腳本,應該顯示我的數據庫中的記錄。問題是:它不顯示所有記錄。我試過了,即使使用最簡單的mysql ($ sql =「SELECT * FROM $ tbl_name」;),但仍有一些記錄丟失(主要是列表中的第一個未顯示)。PHP Array不顯示數據庫中的所有數據
因此,這裏是我的代碼(這是所有1頁):
<?php
$host="localhost";
$username="***";
$password="***";
$db_name="***";
$tbl_name="***";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE rowNameOne >= 0.01 AND rowNameTwo='2013'";
if ($_GET['sort'] == 'one')
{
$sql .= " ORDER BY one ASC";
}
elseif ($_GET['sort'] == 'two')
{
$sql .= " ORDER BY two ASC";
}
elseif ($_GET['sort'] == 'three')
{
$sql .= " ORDER BY three ASC";
}
elseif($_GET['sort'] == 'four')
{
$sql .= " ORDER BY four ASC";
}
elseif($_GET['sort'] == 'five')
{
$sql .= " ORDER BY five ASC";
}
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<body onload="parent.alertsize(document.body.scrollHeight);">
<br />
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" colspan="5">
<font>Titel</font>
</td>
<tr>
<td><a href="pageName.php?sort=one">Titel one</a></td>
<td><a href="pageName.php?sort=two">Titel two</a></td>
<td><a href="pageName.php?sort=three">Titel three</a></td>
<td><a href="pageName.php?sort=four">Titel four</a></td>
<td><a href="pageName.php?sort=five">Titel five</a></td>
</tr>
<tr>
<td colspan="5" class="noBorder">
<?php
while($rows=mysql_fetch_array($result)){
?>
<a href="pageName.php?id=<? echo $rows['id']; ?>" >
<table width="100%">
<tr>
<td><? echo $rows['rowNameOne']; ?></td>
<td><? echo $rows['rowNameTwo']; ?></td>
<td><? echo $rows['rowNameThree']; ?></td>
<td><? echo $rows['rowNameFour']; ?></td>
<td><? echo $rows['rowNameFive']; ?></td>
</tr>
</table>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
<?php
}
?>
</a>
</td>
</tr>
</table>
這是一個非常基本的代碼,容易,可我要說,但仍缺少記錄,不顯示一切是在數據庫。我究竟做錯了什麼?
感謝您的幫助!
就像我說的,即使是代碼$ sql =「SELECT * FROM $ tbl_name」;沒有工作... – 2013-03-23 10:01:24