Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 26th, 2005, 2:48 AM   #1
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
LIMIT question

have a very simple forum type page I made and since I don't know how to really use mysql well I just have all posts to a particular thread list.

I only want the top Ten to show and then at the bottom a link to next results where it will show the next ten. (organized by date; most recent)

I have a topic id which each post corresponds with and a post id to identify each of the posts.

Could someone help me? Maybe some suggestioins on how to... or even a short snippet I can paste in somewhere?

btw, This is part of small DB project I've been trying to do so I'll probably have a couple of other questions once I get this right.

Most of it's done though. Probably 80% so I'm doing decent but it's nothing real complicated either.

Thanks for the help!
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old Jul 26th, 2005, 3:24 AM   #2
prolog
Programmer
 
Join Date: Jul 2005
Location: Germany
Posts: 69
Rep Power: 4 prolog is on a distinguished road
Hi,

a precise shema would be great. At the moment i just can tell you a template how to do such things.

Suppose a shema like this:

id | name | time

SELECT name FROM topics ORDER BY time LIMIT 0,10

You may have to join in additional information.

So far ...
__________________
-= C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do succeed, you will blow away your whole leg. =- Bjarne Stroustrup
prolog is offline   Reply With Quote
Old Jul 26th, 2005, 3:34 AM   #3
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Hey thanks, where you put "ORDER BY time", do I put 'time' or is there a specific function I need to use?

And how do I do a link at the bottom for next pages?

I guess I could determine how many pages I want and pre-program them to display 11-20 and so on. Is there another way? Or am I better off doing it like that? I don't want pages listed for every post ever anyway just maybe 10 pages of 10 posts.
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old Jul 26th, 2005, 3:51 AM   #4
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Ok never mind I got it! Duh, it was so easy.

I just don't get the links to pages with the rest of the posts?

Can you help me with that too?
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old Jul 26th, 2005, 3:52 AM   #5
prolog
Programmer
 
Join Date: Jul 2005
Location: Germany
Posts: 69
Rep Power: 4 prolog is on a distinguished road
Hi,

again without knowing the exact shema i can't show you a specific solution.

ORDER BY time just says that the entries shall be ordered by the values in the time-column. That may be the post-datetime. You can supply an additonal argument wich tells the sort-order (ASC,DESC).

About the link-thing: You could put a variable into the link holding the actual limit.
Suppose you are showing the pages 1 - 10 right now, the link could look sth like this.
<a href="forum.php?limit=10&order=asc">Next page</a>

Your script then takes limit as the startvalue for the SQL-Limit statement.

$query='SELECT name FROM topics ORDER BY time LIMIT '.$_GET['limit'].',10 ';

And again you would show the resultset.
I hope you get the idea.

Regards
__________________
-= C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do succeed, you will blow away your whole leg. =- Bjarne Stroustrup
prolog is offline   Reply With Quote
Old Jul 26th, 2005, 3:54 AM   #6
prolog
Programmer
 
Join Date: Jul 2005
Location: Germany
Posts: 69
Rep Power: 4 prolog is on a distinguished road
Quote:
Originally Posted by dmorales
Ok never mind I got it! Duh, it was so easy.

I just don't get the links to pages with the rest of the posts?

Can you help me with that too?
If they are in a different table and accessable via a relation on the id for example, just join them in.
__________________
-= C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do succeed, you will blow away your whole leg. =- Bjarne Stroustrup
prolog is offline   Reply With Quote
Old Jul 26th, 2005, 5:41 AM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
This might help you with pagination : http://www.phpfreaks.com/tutorials/73/0.php
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC