我試圖爲我的搜索結果做頁面,我的搜索功能工作正常。但是,當我點擊頁碼時。出現此錯誤(下圖):分頁錯誤
說明:未定義指數:用C搜索:\瓦帕\ WWW \ I-文獻\ new.php第8行 ERROR:從下拉
此消息僅應顯示選擇當下拉菜單中沒有輸入並且沒有搜索輸入時。我不知道如何解決這個問題。請幫忙!感謝ü
<?php
//connecting to the database
include 'config.php';
$search = mysql_escape_string($_POST['search']);
$dropdown = mysql_escape_string($_POST['dropdown']);
if (empty($search) && empty($dropdown)) {
die("Please choose your Search Criteria");
}
//max displayed per page
$per_page = 10;
//get start variable
$start = $_GET['start'];
//count records
$record_count = mysql_query("SELECT COUNT(*) FROM document WHERE $dropdown LIKE '%$search%'");
//count max pages
$max_pages = $record_count/$per_page;
if (!$start)
$start = 0;
//display data
$query = mysql_query("SELECT *
FROM document
WHERE $dropdown LIKE '%$search%'
LIMIT $start, $per_page");
echo "<b><center>Search Result</center></b><br>";
$num=mysql_num_rows($query);
if ($num==0)
echo "No results found";
else {
echo "$num results found!<p>";
}
echo "You searched for <b>$search</b><br /><br /><hr size='1'>";
echo "<table border='1' width='600'>
<th>File Reference No.</th>
<th>File Name</th>
<th>Owner</th>
<th>Borrow</th>
</tr>";
while ($rows = mysql_fetch_assoc($query)) {
echo "<tr>";
echo "<td>". $rows['file_ref'] ."</td>";
echo "<td>". $rows['file_name'] ."</td>";
echo "<td>". $rows['owner'] ."</td>";
echo "<td><a href=add_borrower.php?id=" . $rows['id'] . ">Borrow</a></td>";
echo "</tr>";
}
echo "</table>";
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo "<a href='new.php?start=$prev'>Prev</a> ";
//show page numbers
//set variable for first page
$i=1;
for ($x=0;$x<$record_count;$x=$x+$per_page) {
if ($start!=$x)
echo " <a href='new.php?start=$x'>$i</a> ";
else
echo " <a href='new.php?start=$x'><b>$i</b></a> ";
$i++;
}
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='new.php?start=$next'>Next</a>";
?>
'$ record_count = mysql_num_rows(mysql_query(「SELECT * FROM document」));'是獲得可以使用的行的最糟糕方式。它要求數據庫返回表中的所有行。更好'選擇COUNT(*)FROM文檔'。然後你得到一行包含行數的一列。 – ThiefMaster 2010-11-15 02:18:22
謝謝你..我改變了它。 – yash 2010-11-15 02:55:16