Forum Moderators: coopster

Message Too Old, No Replies

Pagination

         

kkonline

4:45 am on Aug 24, 2007 (gmt 0)

10+ Year Member



I read the thread on pages with php at [webmasterworld.com...] and it really cleared my doubt.

When i write

www.example.com/results.php?page=7

then i should get some results [minimum 30 as in the thread example] Now on page 7 ; I should have four links

1> to previous page (page 6)
2> to next page (page 8)
3> to last page (page 120) assuming after page 120 no results are displayed
4> to first page (page 1)

so that means something similar to link combined with $_GET["pageNum"]
BUT HOW?
i wrote something like


<a href="<? echo $_SERVER['HTTP_HOST'];?>/results.php?page=$_GET["pageNum" + 1]>Next page</a>

using above link how to show 1st and last page links(assuming the last page number is far higher than 120, and i don't know exact last number as it's dynamic!)

As shown above the can i make the latest content to display on page 1 and the oldest to show on page 120th .

What if i want reverse; latest on 120th page and oldest on 1st page

vincevincevince

6:08 am on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where do you get your content?

If it is being loaded from MySQL, then your query should be sorted DESC instead of ASC (or the reverse)

i.e. if every article has an article_id, in order:

SELECT * FROM `articles` ORDER BY `article_id` DESC;

Put in your own LIMIT clause as required :)

kkonline

6:19 am on Aug 24, 2007 (gmt 0)

10+ Year Member



Yes the content is in db and each has an id which is autoincremented.

I have created a simple pagination. Now on a page display.php i want to display all the titles as a link

currently i have

[php]while($row = mysql_fetch_array($sql)){
// Build your formatted results here.
echo $row['id']."<br />";
echo $row['content']."<br />";

}[/php]

Instead i want something like

<a href="<?php echo $row['id']">$row['title']</a>

so that for corresponding id i get a corresponding page.

Also i want to give a link to last page . How to know the page number of last page.

the code below gives some parsing error like Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/mysite/public_html/pages.php on line 30

 echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$row['id']\">$row['title']</a>";

vincevincevince

6:42 am on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo "<a href=\"show.php?article=$row[id]\">$row['title']</a>";

mysql_num_rows() may help to find the total page count.