Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mysql中断分页_Php_Mysql - Fatal编程技术网

Php 使用mysql中断分页

Php 使用mysql中断分页,php,mysql,Php,Mysql,我试图让我的分页工作,但我有一个问题,“切换”页面根本不起作用,结果不是真的很好。有人能帮我让它工作吗?因为我一生都无法让它工作,我已经尝试了很多:/ <? if (!(isset($pagenum))) { $pagenum = 1; } $currentpage = 20; $data_p = mysql_query("SELECT * FROM dogs LIMIT $currentpage") or die(mysql_error()); //Th

我试图让我的分页工作,但我有一个问题,“切换”页面根本不起作用,结果不是真的很好。有人能帮我让它工作吗?因为我一生都无法让它工作,我已经尝试了很多:/

<?

 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> ";

 } 

 ?> 


除非您使用register\u globals=on,否则您需要使用
$\u get['pagenum']
获取初始pagenum值,而不是
$pagenum

什么是
$pagenum
?这是一个
$\u GET
请求吗?您还应该更正您的查询:
限制
仅限制结果的数量,对于分页,您应该指定偏移量,您的偏移量应该是
$offset=($currentpage-1)*$pagenum
设置
$pagenum=$\u GET[“pagenum”]如@mesutozer推荐的那样。查询的语法是
SELECT*FROM dogs LIMIT$offset$currentpage