Jump to content

[SOLVED] mysql query select order by alpabets??


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.