Order By
Moderator: General Moderators
Order By
Hi
If I had a database with the following fields in:
Brand
Description
Size
Price
And one record out of 20 with brand 'Adidas' would be:
Brand: Adidas
Description: Samba
Size: 7-10
Price: £40
And one record out of 20 with brand 'Puma' would be:
Brand: Puma
Description: Sprint
Size: 8-11
Price: £60
How would I display all records order by the Brand field ?
I.E. I want to display all records with adidas first - Or display all records with Puma first etc...
can this be done ?
If I had a database with the following fields in:
Brand
Description
Size
Price
And one record out of 20 with brand 'Adidas' would be:
Brand: Adidas
Description: Samba
Size: 7-10
Price: £40
And one record out of 20 with brand 'Puma' would be:
Brand: Puma
Description: Sprint
Size: 8-11
Price: £60
How would I display all records order by the Brand field ?
I.E. I want to display all records with adidas first - Or display all records with Puma first etc...
can this be done ?
- Leviathan
- Forum Commoner
- Posts: 36
- Joined: Tue Sep 23, 2003 7:00 pm
- Location: Waterloo, ON (Currently in Vancouver, BC)
No, you can't display all the records for an arbitrary brand first. You can order by the brand, either ascending or descending, but assuming that there's a middle brand (say Nike; it's alphabetically after Adidas and before Puma), you can't have all the records grouped by brand with Nike coming first. If you really wanted Nike first, you'd have to do 2 queries: one to return Nike, and one to return all the rest. (Of course, to force a specific ordering of ALL your brands, you'd have to do one query per brand).
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
Brands ought to be stored in a lookup (one to many) table - although it is acceptable to de-normalise a relational database in certain circumstances.
You're also missing a unique, integer primary key for catalogue items.
http://www.oreilly.de/catalog/javadtabp ... r/ch02.pdf
Various db articles - see concepts of database design & management:
http://phpcomplete.com/tutorials.php?sec=Databases
Don't mean to be nit-picking: a good db design is the foundation of a php program.
You're also missing a unique, integer primary key for catalogue items.
http://www.oreilly.de/catalog/javadtabp ... r/ch02.pdf
Various db articles - see concepts of database design & management:
http://phpcomplete.com/tutorials.php?sec=Databases
Don't mean to be nit-picking: a good db design is the foundation of a php program.