Welcome to WebmasterWorld Guest from 54.159.44.227

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Help with next/prev theory

How best to do it....

     

Nick_W

5:02 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi all,

Say I have 205 articles in a DB and I want to provide 10 links per page to these articles. (like SERP's)

What's the best/most efficient way of handling it in PHP?

Here's what I've been mulling over:

Retreive all of the unique ID's into an array then work it from there using sessions.

er.... that's all I came up with ;)

Many thanks...

Nick

andreasfriedrich

5:16 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the first search get all rows, on subsequent searches (user hits next/prev botton) use LIMIT to limit results.

Or you can use LIMIT on the first search as well and then get the total number of matching records with a "SELECT count(*) your query".

Not sure which one is faster. I use the first approach. The total number of rows is used for a navigation like "prev 1 2 3 4 5 6 next".

This involves having 4 parameters: offset, no of results to return, no of total results, query string.

Hope this helps.

Andreas

jatar_k

5:46 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I usually use limit and pass the offset. I calculate next, previous, last, first and whatever else just by using the current page range and the max from the id field.

This keeps array size to a minimum and the math to calculate all of the different offsets is very fast.

Nick_W

5:51 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hmmm.... Good stuff guys. Thanks.

Problem is that I'm writing my url's like this:

site.com/catagory // index of articles

site.com/category/11 // individual article

Could I do similar with a structure like that?

I was thinking of maybe having 20 links with descriptions on the index and then a link to all articles which would just be a list of all the titles in the db?

Nick

jatar_k

5:57 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



do you want to list 205 titles on one page?

possible 20 title listing

site.com/catagory?disp=15 // index of articles 15-35

site.com/category/11 // individual article stays the same

Nick_W

6:00 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Ahh.... I begin to see the light!

I'm a bit slow sometimes ;) Only reason I can answer the odd PHP question is the fact that I've been doing it a while!

I was trying to avoid query strings but that's a fair compromise ;)

Nick

andreasfriedrich

6:08 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could still do it without query strings:

site.com/catagory/disp/15

$vars=explode("/", $_SERVER['PHP_SELF']);  
if (is_numeric($vars[2])) {
// single article
} else {
// index of articles
$vars[3] contains offset
}

Andreas

Nick_W

6:14 pm on Oct 23, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Nice!

Thanks very much guys. Good bit of tag team work there ;)

I'm all set to rewrite some functions now ;)

Nick

 

Featured Threads

Hot Threads This Week

Hot Threads This Month