Page 1 of 1

should i loop twice or once???

Posted: Tue Oct 07, 2003 8:02 pm
by Cruzado_Mainfrm
ok i have this simple question, and i don't wanna do bechnmarking because it's obvious what's slower, but i wanna know which one is better, for high traffic i might say:

1.for earch letter of the alphabet(A-Z), query the database to return artist names

or

2.query all the artists and sort them in category trees using array functions, and if that's the best way, how? :D

example:
A
-Abba Teens

B
-Britney Spears

C
-Christina Aguilera

Posted: Tue Oct 07, 2003 9:00 pm
by McGruff
If you don't need or want to paginate, I'd go for one query.

Write a little fn which checks the first letter, writes a new subhead if it's changed, and does nothing if not. Stick that in the while loop where you run through the result rows.

Depending on your page layout and templating preferences, output buffering might be useful to capture the list as a single block of html (which you can then stick in a template somewhere).

Posted: Wed Oct 08, 2003 7:06 am
by evilMind
SELECT * FROM `artists_table` ORDER BY `artist_first_name`,`artist_last_name`;
Is that what you were asking?