Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Help with setlocale results

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' ";
$result=mysql_query($query);

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>';


0
pefstra
Asked:
pefstra
  • 2
1 Solution
 
RoonaanCommented:
Hi,

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?

-r-
0
 
pefstraAuthor Commented:
Hi,

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?
0
 
RoonaanCommented:
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>';

-r-
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now