Ok my is this I am creating a script for a website am designing that will using pagination to draw quotes out from database,
I have done that part quite well, setting up the pagination class and actually making it to print out the results, but I have been trying to make it print with a numbering system - as in each.
I want each quote to have its own number like:
- "One cannot overrun his shadow";
- "foo is not fool, just used in php"
-
"so on and so forth";
Look at my class:
class pagination extends cleanPost{ var $p=1, $max_r,$limits; var $count_all=0,$sql,$total,$table,$totalres,$totalpages; var $r,$i; var $show=10; function setMax($max_r){ $this->p = $this->clean($_GET['p']); $this->max_r = $max_r; if(empty($this->p)) { $this->p = 1; } $this->limits = ($this->p - 1) * $this->max_r; } function setData($table){ $this->table = $table; $this->sql = "SELECT * FROM ".$this->table." LIMIT ".$this->limits.",".$this->max_r.""; $this->sql = mysql_query($this->sql) or die(mysql_error()); $this->total = "SELECT * FROM ".$this->table.""; $this->totalres = mysql_query($this->total) or die(mysql_error()); $this->count_all = mysql_num_rows($this->totalres); // count all the rows $this->totalpages = ceil($this->count_all / $this->max_r); // work out total pages } function displayLinks($show){ $this->show = $show; // How many links to show echo "<br><br>"; if($this->p > 1) // If p > then one then give link to first page { $pagination .= "<div class=\"pagination\"> <a href=?p=1> [first] </a> "; } else { // else show nothing $pagination .= "<div class=\"pagination\">".""; } if($this->p != 1) { // if p aint equal to 1 then show previous text $previous = $this->p-1; $pagination .= "<a href=?p=$previous>«prev</a>"; } else { //else show nothing $pagination.= "<span class=\"disabled\">first</span>".""; } for($i =1; $i <= $this->show; $i++) // show ($show) links { if($this->p > $this->totalpages) { // if p is greater then totalpages then display nothing echo ""; } else if($_GET["p"] == $this->p) { //if p is equal to the current loop value then dont display that value as link $pagination .= $this->p ; } else{ $pagination .= " <a href=?p=".$this->p."> ".$this->p." </a>"; // else display the rest as links } $this->p++; //increment $p } if($_GET["p"] == $this->totalpages) {// if page is equal to totalpages then dont display the last page at the end of links $pagination.= "<span class=\"disabled\">last</span>".""; } else if($_GET["p"] != $this->totalpages) { // $pagination .= "..."; // display dots # $pagination .= "<a href=?p=".$this->totalpages."> ".$this->totalpages." </a>"; } else { // else display the last page link after other ones } if($_GET["p"] < $this->totalpages)// if p is less then total pages then show next link { $next = $_GET["p"] + 1; $pagination .= "<a href=?p=$next> next»</a>"; $pagination.= "<a href=?p=".$this->totalpages."> [last] </a>".""; } $pagination.= "</div> "; echo $pagination;
}
////////// and this is my quote display page
$page= new pagination; $page->setMax(5);//set the maximum quote shown per page $page ->setData("quotes"); $page ->display(); echo "<table border=1 width=100%>"; while ($row = mysql_fetch_array($page->sql)) { echo $num_results = mysql_num_rows($page->sql); echo "<tr>"; for ($i=0; $i <$num_results; $i++) { echo "<td>"; $num_found = $i + 1; echo $num_found.$row['ngwaquote']; echo "</td>"; } echo "</tr>"; } echo "</table><p>"; $page ->displayLinks(4) ;
the results am getting is that if i click on the first number in the pagination link to give me quote.html?p=1
I get them to list it serially page:1 1[quote]A rolling stone gathers no moss.[/quote]
2[quote]A rolling stone gathers no moss.[/quote]
3[quote]A rolling stone gathers no moss.[/quote]
4[quote]A rolling stone gathers no moss.[/quote]
5[quote]A rolling stone gathers no moss.[/quote]but the other page quote.html?p=2 instead of starting from page:2 6[qoute]nothing[/quote] 7[quote]A rolling stone gathers no moss.[/quote]
rather starts counting from one again page:1 1[qoute]nothing[/quote] 2[quote]A rolling stone gathers no moss.[/quote]
I want it to appear like we have in BBC FOOTBALL blogs where comment page number 2 starts from 101 instead of starting all over from 1 again
I hope my question is not too long to understand, if that I am sorry just felt like posting them all for better understanding.