LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2005, 03:11 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Cool General PHP Question


I am curious if there is some sort of built in function of php that sets up multipage results from a query to a database.

So the best example I can think of would be like when you search in google. You see the 1 - 2 - 3 - 4 - 5 - 6 pages of the results... I'm not really too sure why I'm thinking there is some sort of premade function that already does this, but I could have sworn a college professor of mine was showing me it one day a few years back. But perhaps I just dreamt this up...

Anyways, if there is no built in function, which I highly doubt there is, what would you guys suggest the best way to do this would be? I dont need to see any code, just the theory. Thanks for your replies.
 
Old 11-15-2005, 03:34 AM   #2
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
You could execute something like wget to fetch the results from Google, read the content of the webpage into an array, parse it for web links not containing "google" within it so you only kept the external links, then dump the contents of the array into a database. Isn't that hard. Is a similar way to handling the raw streams from something like del.icio.us - you read the content, parse it for the data you want, then store it.
 
Old 11-15-2005, 03:36 AM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
lol no. I didn't mean I want to parse google. I meant I want to query my own database, but when there is more X amount of results I need to seperate into pages. Just like google does with its results. So I'm curious how do I select only like results 11-20 of 0-400 results in a database... that kind of thing. Thanks for replying though.
 
Old 11-15-2005, 03:40 AM   #4
Th3James
LQ Newbie
 
Registered: Jul 2005
Location: Sussex, England
Distribution: SUSE 9.3, Ubuntu Breezy
Posts: 14

Rep: Reputation: 0
The way i would attempt doing it would be to divide the number of results the database gives you for the query by the number of results you want per page, to give you the number of pages the results would be spread across. Using this information, you should be able to view the rows you want on each page with a simple formula, e.g.

display results from
pagenumber*numberofresultsperpage
to
((pagenumber+1)*numberofresultsperpage) - 1

I don't know if there is any built in function. Hope this helps!
 
Old 11-15-2005, 03:43 AM   #5
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Hrm. I see what yur saying, and I suppose I just do a query hit everytime I change pages.
 
Old 11-15-2005, 04:21 AM   #6
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
Guess I didn't understand your question - I see you were simply drawing comparison to google Within your query, specify the range for results, such as "LIMIT 0 , 30" for the first 30 records, then "LIMIT 30 , 30" for the next 30, "LIMIT 60 , 30" for the next 30, etc.
 
Old 11-15-2005, 07:39 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
I see two possibilities:

1/ You maintain a cache on the server.
On first request, you run the whole query, and store the result in $_SESSION. Then you serve the correct subset of the result as requested.

2/ You run dynamic queries (better IMO).
On first request, you run a query that will get all the keys (should be much smaller than the whole result).
Then for each request, you run the whole query with the additional where clause: key in the subset for the requested page, and you serve the result.

Yves.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A truly general question CrazyDelta Linux - General 2 05-17-2005 08:03 PM
general question stealthgate Linux - Software 4 05-09-2005 08:50 PM
A general question, don't know what to do now. qanopus Linux - General 5 11-26-2002 09:30 AM
*N*X general ^M question 5amYan Linux - General 1 06-14-2002 03:43 AM
general question Cheese Linux - Newbie 10 12-01-2001 09:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration