MySQL Forums
Forum List  »  Newbie

Re: Sorting results based on 'another table' ..
Posted by: Chris Stubben
Date: May 30, 2005 11:36AM

Hi,


> Using PHP and MySQL, I have a table with top
> categories and another with subcategories. They
> are related by a two-field table where the id's
> from each category bind them together.


If I understand this correctly, you have three tables: Categories, Subcategories and a linking table. This should just be a three table join to output a tree for a single Category (and then sort by Subcategory name). If you want to sort multiple categories and corresponding subcategories, I would use a path delimited string to sort the output. Check this recent post...

http://forums.mysql.com/read.php?10,27713,27713#msg-27713


> Another question: I keep bumping into the question
> of custom sort order. I have a list of members of
> an association, and they want certain members to
> be listed in a certain order (Chairman first
> etc.). So far the only solution I've come up with
> is adding a 'custom sort field' where they can
> enter a custom sort value for each member (005,
> 010, 015 ..) to have the members sorted the way
> they want. Is there another way?


Check this post.

http://forums.mysql.com/read.php?10,27726,27726#msg-27726

You can use conditionals, but I would create a member_rank table instead with a list of members and a rank for sorting. Join your output to this list of rankings and sort the names by the member's rank.

Chris






>
> Thanks in advance,
> Johnny Skaaning

Options: ReplyQuote


Subject
Written By
Posted
Re: Sorting results based on 'another table' ..
May 30, 2005 11:36AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.