0

I'm having trouble with the following code from a tutorial, it seems very simple but there must be something I'm missing. There is nothing at all where my numbered page menu should be, can anyone see why?

if (isset($_GET["page"])) { // get page number for query
$page = $_GET["page"];
}
else {
$page = 1; // no page number? set it
};

$start_from = ($page-1) * 20;

$query = "SELECT * FROM posts";
$query.= " WHERE isstart = 'y' AND iscomplete = 'n' ORDER BY date DESC LIMIT $start_from, 20";             
$start_from, 20"; // use LIMIT (and options) to make sure only 20 are displayed

$result = mysql_query($query);

$query_count = "SELECT COUNT(post_ID) FROM posts WHERE isstart = 'y'"; 
$count_result = mysql_query($query_count); 
$count_results = mysql_fetch_row($count_result); 
$total_posts = $count_results[0];
$total_pages = ceil($total_posts / 20); // get total pages needed for page menu

for ($i=1; $i<=$total_pages; $i++) { // set the page numbers
$pagelink = "Page: <a href='index_test.php?page=".$i."'>".$i."</a>"; // make the page menu
}; 

$top_body_text = '<p align="left">'.$pagelink.'</p>';

Currently my statement echo'ing $pagelink creates noting.

4

2 回答 2

0

首先,这一行有错误

$start_from, 20"; 

它应该是

   $start_from = 20; 

最后,您需要在 for 循环中回显“$pagelink”,以便查看列出的每个页码。下面的例子:

if (isset($_GET["page"]))
 { // get page number for query
   $page = $_GET["page"];
 }
else {
   $page = 1; // no page number? set it
 };

 $start_f = 20; // use LIMIT (and options) to make sure only 20 are displayed
 $start_from = ($page-1) * $start_f;

 $query = "SELECT * FROM posts";
 $query.= " WHERE isstart = 'y' AND iscomplete = 'n' ORDER BY date DESC LIMIT $start_from, 20";             



  $result = mysql_query($query);

 $query_count = "SELECT COUNT(post_ID) FROM posts WHERE isstart = 'y'"; 
 $count_result = mysql_query($query_count); 
  $count_results = mysql_fetch_row($count_result); 
 $total_posts = $count_results[0];

 $total_pages = ceil($total_posts / 20); // get total pages needed for page menu

 for ($i=1; $i<=$total_pages; $i++)
  { // set the page numbers
   echo $pagelink = "Page: <a href='index_test.php?page=".$i."'>".$i."</a>"; ///Echo here
  }; 
  $top_body_text = '<p align="left">'.$pagelink.'</p>';
于 2013-11-14T17:20:39.573 回答
0

删除这一行——它什么也没做:

$start_from, 20"; // use LIMIT (and options) to make sure only 20 are displayed

你已经在这里定义了 $start_from :
$start_from = ($page-1) * 20;

然后检查你的结果,看看你是否都准备好了。

于 2013-11-14T17:17:07.087 回答