将下一个按钮添加到php分页脚本。 它简短而简单

This is the first pagination script I've coded with help from a friend. I customized it a bit and want to also add NEXT and PREVIOUS buttons. Here is my code.

$per_page = 6;

$pages_query = mysql_query("SELECT COUNT(`user_id`) FROM `users`");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);

$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;

$query = mysql_query("SELECT `username` FROM `users` WHERE `active` = 1 LIMIT $start,         $per_page");
while ($query_row = mysql_fetch_assoc($query)) {
  echo '<p>', $query_row['username'] , '</p>';
}

//previous (this is where the previous button would go)

if ($pages >=1 && $page <=$pages) {
  for ($x=1; $x<=$pages; $x++) {
    echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a         href="?page='.$x.'">'.$x.'</a> ';
  }
}

I've simplified the script and have removed the last page first page buttons. I also exluded the php tags and mysql connection

This is pretty simple

add this before loop starts with $_GET global value

for your previous if(isset($_GET['page']) && $_GET['page'] > 1){ href($_GET['page'] -1) }

for your next if(isset($_GET['page']) && $_GET['page'] < $pages){ href($_GET['page'] +1) } you can add this with subtract and add operator

however thanks for sharing the code i got really easy way to use your code with my custom php application too :)

enter image description here