[PHP] Arrays and Alphabetical order

2003-07-22 Thread Don Mc Nair
Hi folks

I am trying to print out a table of elements in alphabetical order. I have
an SQL query which sorts out the data in order and am using 'while ($info
=(mysql_fetch_row...etc)) to read the data array. 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.

Any help is appreciated.

Don


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread David Nicholson
Hello,

This is a reply to an e-mail that you wrote on Tue, 22 Jul 2003 at
17:40, lines prefixed by '' were originally written by you.
 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.

How about:
for($i=a;$i=z;$i++){
echo H1Items beginning with the letter $i/H1;
$arrayposition = 0;
while(strtolower(substr($data[$arrayposition],0,1))==$i){
echo $data[$arrayposition] . BR /;
$arrayposition++;
}
}

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Liam Gibbs
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 trth$previousfirstletter/th/tr;
   }
   echo trtd$result/td/tr;
}

echo /table;

It's untested, but I believe it will work.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Evan Nemerson
/* UNTESTED - and prolly could be more efficient */
$c = $d = '';
natsort($info);
foreach ( $info as $i ) {
$d = substr($i, 0, 1);
if ( $d != $c )
echo \n;
echo $i;
$c = $d;
}


On Tuesday 22 July 2003 09:40 am, Don Mc Nair wrote:
 Hi folks

 I am trying to print out a table of elements in alphabetical order. I have
 an SQL query which sorts out the data in order and am using 'while ($info
 =(mysql_fetch_row...etc)) to read the data array. 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.

 Any help is appreciated.

 Don


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

-- 
He who fights too long against dragons becomes a dragon himself; and if you 
gaze too long into the abyss, the abyss will gaze into you.

-Nietzche


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php