Sign in to follow this  
RomeoJGuy

[web] Hello a quick php/MySQL issue! (ignoring letter case of a sort of names)

Recommended Posts

I have made this website where I have implemented into a Game Mod a system to send scores from in-game (its an SP mod) to the webserver so you can see how you did in comparison to others. Personal Score is how many enemies you killed and team score is how many enemies your allies killed. The problem is that the name field is not sorting while ignoring case. I tried searching to find articles dealing with making a sort ignore case to no avail. Do you need a certain type for the field for it to sort while ignoring case? Here is the site: www.antliontroopers.romeojguy.com

Share this post


Link to post
Share on other sites
Quote:
Original post by RomeoJGuy
I have made this website where I have implemented into a Game Mod a system to send scores from in-game (its an SP mod) to the webserver so you can see how you did in comparison to others. Personal Score is how many enemies you killed and team score is how many enemies your allies killed.

The problem is that the name field is not sorting while ignoring case. I tried searching to find articles dealing with making a sort ignore case to no avail.

Do you need a certain type for the field for it to sort while ignoring case?

Here is the site:

www.antliontroopers.romeojguy.com


What kind of sort ? You mean an SQL order by ?

If so, the technique goes like this. (Note that I don't know mySql very well, so here's Oracle functions, they probably have an equivalent if they aren't implemented as is.


SELECT foo, TO_LOWER(foo) FROM bar ORDER BY TO_LOWER(foo)

If you do not mean an order by, then the technique is the same. Convert everything to lower_case, sort, and grab the corresponding original.

Share this post


Link to post
Share on other sites
According to the MySQL Manual, section 3.3.4.4, character-type columns should sort case insensitively by default.

If you wanted to force case sensitive sort, then you'd use "ORDER BY BINARY column_name"


Edit: Looking at the SELECT statement syntax, the ORDER BY clause may be used with a column name, position index, or expression, so xMcBaiNx's solution may work using MySQL equivalents:

SELECT [columns] FROM [table] ORDER BY LOWER(name_col) ASC

though I havn't tested this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this