Re: Arrays and Alphabetical order

From: Date: Tue, 22 Jul 2003 16:53:11 +0000
Subject: Re: Arrays and Alphabetical order
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-156268@lists.php.net to get a copy of this message
<<I need it to echo out a table with all the A's first, then a blank line, then all the B's, a blank line and so on. I could write 26 different queries, one for each letter of the alphabet, but surely there is a tidier way.>> Do a query, sorting by the field you need alphabetized. Then do this (and tidy it up as you need): echo "<table>"; while($result = mysql_fetch_row$(query)) { if(substr($result, 0, 1) != $previousfirstletter) { $previousfirstletter = substr($result, 0, 1); echo "<tr><th>$previousfirstletter</th></tr>"; } echo "<tr><td>$result</td></tr>"; } echo "</table>"; It's untested, but I believe it will work.

« previous php.general (#156268) next »