[SOLVED] mysql_query question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
charp
Forum Commoner
Posts: 85
Joined: Sun Oct 26, 2003 3:00 pm
Location: Rancho Cucamonga, Calif. USA

[SOLVED] mysql_query question

Post 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]
Last edited by charp on Fri Dec 26, 2003 11:38 am, edited 1 time in total.
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Change the second condition to <f and that code appears to be fine.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: mysql_query question

Post 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]
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

mysql is case insensitive
User avatar
charp
Forum Commoner
Posts: 85
Joined: Sun Oct 26, 2003 3:00 pm
Location: Rancho Cucamonga, Calif. USA

Post by charp »

Thank you uberpolak, Weirdan and aquila125. Each reply was helpful!
Post Reply