Help with setlocale results

Posted on 2006-05-04
Last Modified: 2013-12-12
Hi, I have done a script to order by sname in greek, but the results aren't in the right order. Obviously something is wrong, but I dont know what. Could anybody help please? Here is my script:

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
$query="select id, sname, fname from bios WHERE list = '$section' AND publ_status = '11' ";

while ($row = mysql_fetch_array($result)) $data[] = "<a href=show.php?id=" .$row[0] .">" .$row[1] . " " .$row[2] . "</a>" ;

setlocale (LC_ALL, 'el_GR');
sort($data, SORT_LOCALE_STRING);

echo implode('<P>',$data).'</P>';

Question by:pefstra
    LVL 49

    Expert Comment


    Because you are sorting html tags, you most probably are sorting on the id=".$row[0]." part rather than on the actual sname/fname part.

    Which leaves to wonder why you don't use ORDER BY clause in mysql?


    Author Comment


    ORDER BY doesnt help, because the colation of my db is latin 1, and I cant change it. Is it possible this script to short by sname?
    LVL 49

    Accepted Solution

    You can try using:

    while ($row = mysql_fetch_array($result)) {
      $data[$row[1].'/'.$row[2]] = "<a href=show.php?id=" .$row[0] .">" .$row[1] . " " .$row[2] . "</a>" ;

    setlocale (LC_ALL, 'el_GR');
    ksort($data, SORT_LOCALE_STRING);

    echo '<p>'.implode('</p><p>',$data).'</p>';


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now