Jump to content

[SOLVED] Alphabetical Sort ... SQL query issue


kjtocool

Recommended Posts

I am working on an Alphabetical sort, and am wondering if there is an easier way to handle finding numerical named movies like: "88 Weeks." Currently I have to use something like:

 

$query = "SELECT * FROM myCinema_Movies WHERE (movieName like '0%' or movieName like '1%' or movieName like '2%' or movieName like '3%' or movieName like '4%' or movieName like '5%' or movieName like '6%' or movieName like '7%' or movieName like '8%' or movieName like '9%') order by movieName";

 

Is it possible to simplify it, or am i stuck using this?

Link to comment
Share on other sites

Forgive my ignorance, but surely "ORDER BY movieName" is an alphabetical sort...?

 

Of course.

 

The problem with that is, I want to get JUST movies that start with A, B, C, etc, and I want an option that is "Other" and includes just movies starting with numbers, etc.  Since I need a result set, and since I don't know exactly how many of these movies there are, a simple ORDER BY is not sufficient.

 

SELECT * FROM myCinema_Movies WHERE movieName < 'a'

 

The above, is exactly what I was looking for.

Link to comment
Share on other sites

What they are looking for is not really what the title of the post says. They know what a user clicks A, how to select all movies that start with A, but they wanted know how to find movies starting with any numeric value.

Link to comment
Share on other sites

Because I want a result that excludes anything starting with a letter.

Well, a REGEXP can do that, too.

 

Can regex be used in MYSQL queries? You wouldn't want to do that with PHP, as then you would have to load ALL the records, and filter them out after as you parse them. It's much better to filter out from a DB level.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.