• You are not logged in. | Login

Post a reply

  • Index
  •  » Help me!
  •  » How to make sorting in alphabetical order?

January 17, 2007 8:49 am

franzkafka
Member
Ranks

How to make sorting in alphabetical order?

Hallo! I have such a question.
I need to create a cities’ base. In a MySQL-table the data have following form: ID Len Country City. ID is a number, Len is the first symbol in the name of a country.
The result is put out like this:

$query="SELECT DISTINCT `Country` FROM `ay_world` WHERE `Len` = '$char'"; //$char any letter transmitted with other script 
$res=mysql_query($query) or die ("Error;)");
$kol=mysql_num_rows($res);
if($kol<=50){
for ($i=0; $i<$kol; $i++)
{
$count=$i+1;
$Country_sql = mysql_result($res,$i,"Country");
echo("$count. <A HREF='a-z.php?country=$Country_sql'>$County_sql</A><br>");
}

 

 

January 17, 2007 8:50 am

franzkafka
Member
Ranks

Re: How to make sorting in alphabetical order?

A list of countries beginning with letter $char is put out. But the problem is that they aren’t put out in the alphabetical order. Their output occurs according to ID. Those who have high ID are written at the top of the list.
How is it possible to put out list in the alphabetical order?
Thanks.


 

 

January 17, 2007 8:55 am

bobbee
Member
Ranks

Re: How to make sorting in alphabetical order?

With consideration to register:
SQL

SELECT DISTINCT `Country` FROM `ay_world` WHERE `Country` LIKE BINARY `$char%` ORDER BY `Country`

Without consideration to register:
SQL

SELECT DISTINCT `Country` FROM `ay_world` WHERE LOWER(`Country`) LIKE BINARY LOWER(`$char%`) ORDER BY `Country`


 

 

January 17, 2007 8:56 am

franzkafka
Member
Ranks

Re: How to make sorting in alphabetical order?

bobbee, it doesn’t work i.e. die ("Error;)


 

 

January 17, 2007 9:01 am

phppat
Member
Ranks

Re: How to make sorting in alphabetical order?

mysql_query($query) or die ("Error;)") for mysql_query($query) or die (mysql_error())


PHP monster

 

 

January 17, 2007 9:02 am

franzkafka
Member
Ranks

Re: How to make sorting in alphabetical order?

Actually I’ve changed on

SELECT DISTINCT `Country` FROM `ay_world` WHERE `Len` = '$char' ORDER BY `Country`

It seems to function properly.
There was Unknown column 'E%' in 'where clause'
If you change inverted commas from ` to ' in (`$char%`), no errors are shown up; but there was no result as well as if table was blank.


 

 

January 17, 2007 9:04 am

bobbee
Member
Ranks

Re: How to make sorting in alphabetical order?

What is Len? The first letter in the name of a country? Then the data base is projected rather stupidly.


 

 

January 17, 2007 9:05 am

franzkafka
Member
Ranks

Re: How to make sorting in alphabetical order?

bobbee , maybe it’s stupid but it takes only one cell. And frankly speaking it’s easier for me to examine data bases within MyPHPAdmin this way.


 

 

January 17, 2007 9:05 am

bobbee
Member
Ranks

Re: How to make sorting in alphabetical order?

"... where 'country' like binary'".$char."%' order by country" would be simpler and more correctly. It means to take the first letter of a country not a separate field.


 

 
  • Index
  •  » Help me!
  •  » How to make sorting in alphabetical order?
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services