基本上,我想通過使用@rownum顯示來自表的行數和第一頁的數據,但是當我們轉到下一頁時,我們開始再次排第一。如何通過連接獲得Mysql rownum
查詢代碼:
$sql = "SELECT @rownum:[email protected]+1 as rownum, t.*FROM (SELECT @rownum:=0) r, (select * from tbl) t
LIMIT $Page_Start , $Per_Page";
pagenation代碼:
$objConnect = mysql_connect("localhost","user","pass") or die("Error Connect to Database");
`enter code here`$objDB = mysql_select_db("WEB");
$strSQL = "SELECT * FROM line ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 2; // Per Page
$Page = mysql_real_escape_string($_GET["Page"]);
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
pagenation用法:
if($Prev_Page)
{
echo "<a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'> Back</a>   ";
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next</a> ";
}
所以我想行號後頁面 例如,第1不斷增加頁第1-5行和第2頁應該是6-10這樣的東西
個非常感謝
你能在你的SQL查詢添加一個參數來初始化ROWNUM到pagestart而不是0?這樣,它應該隨着頁面增加而增加,我認爲。 – sgeddes