Hiya everyone, this is my first post so I would just like to introduce myself. My name is Tina. I am 18 and from the UK. I have been doing HTML and CSS for a while now and am just starting to learn PHP.
I have added pagination to a page and I want it to select only the records that do not equal 'Admin'. The query reflects this but unfortunately the page numbering that appears leaves blank spaces for the other records forcing extra pages with no content. How can I limit the pagination based on just the records that have a particular type? Thanx
<?php
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$query = "SELECT * FROM announcements WHERE anntype != 'Admin' ORDER BY annwhen DESC";
$result = mysql_query($query);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 10;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM announcements WHERE anntype != 'Admin' ORDER BY annwhen DESC $limit";
$result = mysql_query($query);
if ($numrows <= 0) {
echo "There are currently no announcements";
} else {
while($row = mysql_fetch_array($result))
{
$anntype = $row["anntype"];
$annname = $row["annname"];
$anndetail = $row["anndetail"];
$annwhen = $row["annwhen"];
echo "<div>";
echo "<h2>" .$annname. "</h2>";
echo $anndetail. "<br />";
echo "<div class=\"posted\">Posted on: " .date('l, F d, Y', strtotime($row['annwhen'])). " at: " .date('H:i:s', strtotime($row['annwhen'])). "</div><hr />";
echo "</div>";
}
}
if ($lastpage == 1 OR $pageno == 1) {
echo "";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>First</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>Previous</a> ";
}
echo " (Page $pageno of $lastpage) ";
if ($lastpage == 1 OR $pageno == $lastpage) {
echo "";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>Next</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>Last</a> ";
}
?>