Page 1 of 1

[SOLVED] mysql_query question

Posted: Wed Dec 24, 2003 3:21 pm
by charp
I'm trying to select names from a table that fit inside an alphbetical range. The code below seems to be working, but I'm wondering if there's a better way. Here's the code that I think selects all names that start with D or E:

Code: Select all

$staffnames=mysql_query("SELECT name FROM $table WHERE name>='d' AND name<='Ez' ORDER BY name ASC");
Does case matter here? If I made the first condition (name>='D'), would that skip over a name of "davidson"?

For my second conditon (name<='Ez'), should I have used (name<'f')? I'm wondering if <='Ez' would skip over the name "Ezzy".

And that brings me to one last question (for now): how does PHP and/or MySQL order characters? Can anyone point me to a reference?

Thanks in advance!


(Edited : Infolock Moved to Database forum )[/b]

Posted: Wed Dec 24, 2003 3:30 pm
by uberpolak
Change the second condition to <f and that code appears to be fine.

Re: mysql_query question

Posted: Wed Dec 24, 2003 4:42 pm
by Weirdan
charp wrote:And that brings me to one last question (for now): how does PHP and/or MySQL order characters? Can anyone point me to a reference?
http://www.mysql.com/doc/en/Character_sets.html
The character set determines what characters are allowed in names and how strings are sorted by the ORDER BY and GROUP BY clauses of the SELECT statement.
in php '>' and '<' and [php_man]strcmp[/php_man] compare the strings according to C locale. On the other hand [php_man]strcoll[/php_man] compares the strings according to currently set locale.
[php_man]setlocale[/php_man]
Further reading:
http://www.debian.org/doc/manuals/intro-i18n/
[google]i18n L10n[/google]

Posted: Thu Dec 25, 2003 11:02 am
by aquila125
mysql is case insensitive

Posted: Fri Dec 26, 2003 11:35 am
by charp
Thank you uberpolak, Weirdan and aquila125. Each reply was helpful!