2014-03-18 58 views
-1

我想讓我的分頁工作,但即時通訊有問題,「切換」pagen不會工作,結果是不是真的工作得很好。誰能幫得到它的工作的原因我不能爲我的生命得到它的工作,我已經嘗試過這麼多:/破碎的分頁與mysql

<? 

if (!(isset($pagenum))) 

{ 

$pagenum = 1; 

} 

$currentpage = 20; 
$data_p = mysql_query("SELECT * FROM dogs LIMIT $currentpage") or die(mysql_error()); 


//This is where you display your query results 

while($info = mysql_fetch_array($data_p)) 

{ 

    $id=$info['id']; 
    echo '<a href="/index.php?dogs='. $id .'"> 
     <img src="/thumbs/'. $id .'.jpg" width="100" height="100" alt="" /> 
    </a>'; 

echo "<br>"; 

} 

echo "<p>"; 


// This shows the user what page they are on, and the total number of pages 

echo " --Page $pagenum of $last-- <p>"; 


// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. 

if ($pagenum == 1) 

{ 

} 

else 

{ 

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; 

echo " "; 

$previous = $pagenum-1; 

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; 

} 


//just a spacer 

echo " ---- "; 


//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links 

if ($pagenum == $last) 

{ 

} 

else { 

$next = $pagenum+1; 

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; 

echo " "; 

echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; 

} 

?> 
+0

什麼是'$ pagenum'?這是一個'$ _GET'請求嗎? – samayo

回答

0

除非你正在使用register_globals工作=上,你需要獲得與$_GET['pagenum']初始頁次值而不是$pagenum

+1

而且你應該更正你的查詢: 'LIMIT'只限制結果數量,對於分頁你應該指定偏移量 你的偏移量應該是'$ offset =($ currentpage - 1)* $ pagenum'總是在輸入' $ pagenum = $ _GET [「pagenum」];'@mesutozer建議你。你的查詢的語法是'SELECT * FROM dogs LIMIT $ offset,$ currentpage' – Olvathar