嘿,我想添加一個按鈕(鏈接),點擊時會過濾分頁結果。如何在此分頁中添加過濾器按鈕?
我是新來的PHP(和編程一般),想添加一個按鈕,像「汽車」,並點擊時,它在我的分頁腳本更新了2個MySQL查詢,在這裏看到:
正如你可以看到,汽車硬編碼類別中,我希望它是動態的,所以當單擊鏈接時,它會將任何id或類位於查詢的類別部分中。
1:
$record_count = mysql_num_rows(mysql_query("SELECT * FROM explore WHERE category='automotive'"));
2:
$get = mysql_query("SELECT * FROM explore WHERE category='automotive' LIMIT $start, $per_page");
這是我使用的整個電流的PHP分頁腳本:
<?php
//connecting to the database
$error = "Could not connect to the database";
mysql_connect('localhost','root','root') or die($error);
mysql_select_db('ajax_demo') or die($error);
//max displayed per page
$per_page = 2;
//get start variable
$start = $_GET['start'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM explore WHERE category='automotive'"));
//count max pages
$max_pages = $record_count/$per_page; //may come out as decimal
if (!$start)
$start = 0;
//display data
$get = mysql_query("SELECT * FROM explore WHERE category='automotive' LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$name = $row['id'];
$age = $row['site_name'];
echo $name." (".$age.")<br />";
}
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
//show prev button
if (!($start<=0))
echo "<a href='pagi_test.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='pagi_test.php?start=$x'>$i</a> ";
else
echo " <a href='pagi_test.php?start=$x'><b>$i</b></a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
echo " <a href='pagi_test.php?start=$next'>Next</a>";
?>
這類作品。它會進入第一頁,但是當我點擊另一個頁碼如[2]時,什麼都不顯示。有想法該怎麼解決這個嗎? – ClarkSKent 2010-04-26 02:27:48
nvm,我添加category = $ category&url後點擊的項目。謝謝您的幫助! – ClarkSKent 2010-04-26 02:33:23