homepage Welcome to WebmasterWorld Guest from 54.242.140.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Help with next/prev theory
How best to do it....
Nick_W

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



 
Msg#: 1094 posted 5:02 pm on Oct 23, 2002 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1094 posted 5:16 pm on Oct 23, 2002 (gmt 0)

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

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



 
Msg#: 1094 posted 5:46 pm on Oct 23, 2002 (gmt 0)

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

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



 
Msg#: 1094 posted 5:51 pm on Oct 23, 2002 (gmt 0)

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

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



 
Msg#: 1094 posted 5:57 pm on Oct 23, 2002 (gmt 0)

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

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



 
Msg#: 1094 posted 6:00 pm on Oct 23, 2002 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1094 posted 6:08 pm on Oct 23, 2002 (gmt 0)

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

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



 
Msg#: 1094 posted 6:14 pm on Oct 23, 2002 (gmt 0)

Nice!

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

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

Nick

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved