Jump to content

[SOLVED] mysql query select order by alpabets??


yami007

Recommended Posts

how can i display the contents ordered by alphabets?

well, i want to get the results this way:

<div>A</div>

<div>akon...</div>

<div>amine...</div>

<div>amel...</div>

<div>B</div>

<div>bryan...</div>

<div>britanie...</div>

so on.....

 

please help

Okay and whats the problem ?

its basically a while loop check first char is its diffrent then echo the new one

quick draft untested example

$letter = "";
while($row = mysql_fetch_array($result))
{
$fletter = substr($row['0'],0, 1);
if($letter != $fletter)
{
$letter = $fletter;
echo "$letter<br>";
}
echo $row['0']."<br>";
}

 

the rest is basically CSS/HTML

ok guys that's how i turned this code into :

<?php 
 $query ="SELECT * FROM singers ORDER BY name";
 $singers_set = mysql_query($query);
 while ($singers = mysql_fetch_array($singers_set)) {
 $fletter = substr($singers['name'],0, 1);
 if ($letter != $fletter) {
   $letter = $fletter;
   echo "$letter<br>";
 }
 echo $singers['name']."<br>";
 }
?>

Sorry for late reply Mark Baker is correct if you used "SELECT name  FROM singers ORDER BY name" the code should of worked

 

i didn't know the field names being used and i don't really test the code i just enter it directly..

anywho glade you got it sorted

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.