MySQL results not showing correctly.

I created a website that uses a database to search results, however I just imported new results and noticed that these results are not being displayed in alphabetical order as they should be.

Here’s the query I’m using:
SELECT * FROM songdb WHERE artist LIKE ‘%$q%’ OR (artist AND title LIKE ‘%$q%’) OR title like ‘%$q%’ ORDER BY title ASC LIMIT $startrow, 10

It displays all of the results, but it is putting the new records at the end, instead of where they should be alphabetically, I’m stumped.

Any help is appreciated.

Can you give an example?

Yea, for example. My records will show as this in the database:

Alejandro
Lady Gaga

Dance In The Dark
Lady Gaga

Do What U Want (Explicit)
Lady Gaga feat. R. Kelly

Marry The Night
Lady Gaga

Dope
Lady Gaga

“Dope” should be showing up in the “D’s” using that query, it was imported after all the others, it’s showing the order of the records in the DB, not alphabetically by the artist field (in this case “lady gaga”, and then by title…)

Check the entries that are coming in last for errant spaces in the beginning.

I actually already did, there are no spaces, no punctuation that might be throwing it off. Sorry should have included that already.

Do a basic query in mySQL and see if you get the same results. The only thing I know of that could change the order is something like a space in front that would cause it to not order properly, the other doesn’t apply and is when you designate numbers as varchar then numbers don’t order correctly.

Sponsor our Newsletter | Privacy Policy | Terms of Service