Hi everyone,

i was wondering if anyone out there knows how to list mySQL results in alphabetical order with each letter having its own group [probably doesn't make much sense, so...].

So for example it would look like this:

A
All the people whos name begins with A.

B
All the people whos name begins with B.

C
All the people whos name begins with C

and so on and so on.

The only way i know how to do this would be to make separate recordsets for each letter of the alphabet [abit long winded] and i was hoping someone might know how to do this with a for loop or something similar.

any suggestions would be brilliant 🙂

Thanks
TOM

    Here's a recent thread involving something similar. Only difference is that you want an A, B, C, etc. instead of just a rule.

      Hi and thanks, that got me going and i've managed to get enteries listing under the approiate letter. see here. .

      But at the moment for example there's mulitple enteries under R, and it displays the R above for every entry under R. 😕

      Here's my code so far, i've added this to a dreamweaver repeat region loop.

      $alphabets = array ( "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" );
      //all letters of alphabet

      	do {	//DW loop for enteries
      
      	$first_let = substr($row_alpha['company'],0,1); // gets first letter of company name
      	$first_let = ucfirst(strtolower($first_let)); //capitalise first letter 
      
      
      	for($i=0;$i<=count($alphabets);$i++) { //loop thur alphabet						
      			$letter = $alphabets[$i];
      
      			if($first_let == $letter){ // if company name first letter matches letter in alphabet, echo the letter	
      				echo "<br />". $letter ."";
      			}
      	 }

      I guess i need to record the previous letter when the company names' first letter matches a letter of the alphabet so it doesn't get repeated!
      Not sure how to go about doing that, any ideas!??

      thanks again
      Tom 🙂

        Write a Reply...