how 2 do this?(mysql)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

how 2 do this?(mysql)

Post by qads »

hi,
i am makeing a forum and i have ranking table

here is ranking table layout:
ID:1
title: user
required_posts = 0

ID: 2
title: coder
required_posts: 15
____________________
here is users table:
ID: 1
Username: user1
posts: 4
______________________
so, user1 has a rank title of user by looking at this but how do i do this in a query? how do i get the correct rank title based on number of posts?

i can't seem to understand that :x

thanks alot for your time
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

something like

SELECT * FROM ranks WHERE required_posts < '$numofposts'

then just grab the first row or the last row, i am not sure
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

I think you should be better using

Code: Select all

SELECT * FROM ranks WHERE required_posts <= '$numofposts'
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

nope, what i have done is this:

Code: Select all

select * from ranks where required_posts < $noofposts order by ID DESC limit 1
this gets only one record and cos it is in desc order it gets the correct one :P
Post Reply