Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing certain number of records

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
hey guys,
i'm wanting to put a "View: 10 | 50 | 100 | ALL" thingy on my site so people can choose how many records they want to see at once. How should I do this so that it remembers what they want. Cookies? Sessions? Is there a tutorial somewhere that guides you through this? i'm a newbie ;)

Thanks.
 
The best way is the using of sessions.

it's easy, you only have to limit the query to the number user choose.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
If the records are stored in a database such as MySQL, you can use the LIMIT function in the SQL query. You can remember what they want by cookies, get variables, or sessions. I have used the get variables mostly (since some browsers/users dont use cookies and sessions are a little overkill for such a small amount of data"

Here is my example:

// QUERY CONSTRUCTION
$query = "SELECT fields FROM table"
if ($pt < 101 && $pt > 9) $query .= &quot; LIMIT $pt&quot;;


// LINK CONSTRUCTION
echo &quot;VIEW <a href='page.php?pt=10'>10</a> |
<a href='page.php?pt=50'>50</a> |
<a href='page.php?pt=100'>100</a> |
<a href='page.php?pt=101'>ALL</a> &quot;;


You then just have to include the $pt variable in all of your links that pertain to these set of records. If you know your entire audience is using cookies then you could store the variable into cookies. If you already have sessions activated for other purposes then you could just store that variable into the session data.

You could also have them traverse through the records by setting the LIMIT with two variables ('Limit X,Y') where X is the starting record and Y is the number of records to be displayed.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top