GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 31-Mar-2006, 06:25
El Hadji El Hadji is offline
New Member
 
Join Date: Feb 2006
Posts: 2
El Hadji is on a distinguished road

Page Breaks


Hi,

I would like to enter a search value in a form (done in html) and send the value to the PHP file that would query the my-SQL database table and display the results showing a specified number of pages and allowing to move to the next page until all is done. NOTE: the form and the PHP file are two separate files.

Pliz help.
  #2  
Old 31-Mar-2006, 11:33
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Page Breaks


This is actually fairly easy. For the first page of results... let's say that you only want to show 10 items at a time. In your MySQL query, use the LIMIT keyword to limit the amount of rows that mysql returns.

For instance:

Code:
SELECT * FROM users WHERE age > 21 LIMIT 0,10

That query will get you the first 10 results from that query. The 0 after the LIMIT tells yuo where to start and the 10 tells you how many rows to get. Now, to get the next 10 results, all you have to change is this:

Code:
SELECT * FROM users WHERE age > 21 LIMIT 10,10

That will start at the 11th result (like arrays 0 is the first element... so 10 is actually the 11th) and get the next 10.

So one easy way to do that in PHP is to pass the values of where to start and how many elements to get as URL arguments.

Code:
http://www.whatever.com/results.php?lowlimit=10&n=10

(I only put that in code tags because it wouldn't quit hyperlinking the text. It's only an example... not a link)

Then you can use those values to insert into your MySQL query and viola. The lowlimit variable holds the value of where to start, and the n variable tells you how many rows to return. So, all you have to alter in each pages "NEXT" link is to add 10 to the lowerlimit variable. As for the "PREVIOUS" link, you just need to subtract 10.
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #3  
Old 26-Apr-2006, 07:09
dopee dopee is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: south africa
Posts: 109
dopee will become famous soon enough

Re: Page Breaks


wow that just helped me out a lot thanx TreyAU21 ...i was always doing that by selecting, adding, all rows into one large array and then displaying certain rows within the array doh! Is this method secure to injection attacks or what can u do to allow only relevant variables being allowed in the query?
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Rank vs. Google listing crystalattice Search Engine Optimization Forum 8 15-Mar-2007 04:49
Loading a php page in an iframe from javascript Clive73 Web Design Forum 0 18-May-2005 07:10
next page skyloon MySQL / PHP Forum 5 17-Oct-2004 13:04
[script] E-mail webmaster error page BobbyDouglas PHP Code Library 0 19-Aug-2003 21:10
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 11:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:51.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.