Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Cancelling out 'The ' in a mysql query
Old 12-21-2007, 02:36 PM Cancelling out 'The ' in a mysql query
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
If I ever get great at php its going to be entirely because of you guys with all the advice Im getting here. And on that note, Im back for more !

I have two different pages with essentially the same problem:
PHP Code:
$query " SELECT* FROM mreleased WHERE name LIKE '$letsel%'"
PHP Code:
$result mysql_query("SELECT * FROM mreleased WHERE genre='$pqualifier' ORDER BY name") or die(mysql_error()); 
In the first one it just looks for any name that starts with the given letter. Then for the second it orders the list by name within the subcategory.

My problem is that since this is a database of movies there is the incredibly irritating occurence of movie titles starting with the word 'The'. Now I could retrieve the entire database and then use php to remove 'The' and then (assuming there is a command to order in php, i havent looked yet) sort by name in PHP. But seeing as mysql already does the sorting/searching for me I would rather avoid that.

Is it possible to search for and cancel out part of a sql string?

Like SELECT * FROM mreleased WHERE name!='The %' & WHERE name LIKE'$letsel%'

That last line was just me fishing, from what Ive read you cant even have '&' in a mysql statement but hopefully that gives you an idea of what Im trying to achieve.

Thanks,
Truly.
Truly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-21-2007, 02:55 PM Re: Cancelling out 'The ' in a mysql query
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use negation and AND

... WHERE name NOT LIKE 'the %' AND name LIKE '%search_pattern%' ...
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-21-2007, 05:14 PM Re: Cancelling out 'The ' in a mysql query
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I have seen a lot of movie titles listed with "The" appended on the end like: Wizard Of Oz, The

Of course this has no benifit to you now if you already have tons of moview titles already strored!
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-21-2007, 10:49 PM Re: Cancelling out 'The ' in a mysql query
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Yeh I was thinking of that as an option but I wanted to a) find out how to do it and b) be able to still output the movie name correctly.

Thanks guys!
Truly is offline
Reply With Quote
View Public Profile
 
Old 12-22-2007, 04:56 PM Re: Cancelling out 'The ' in a mysql query
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Sorry guys I think I did a bad explanation of my problem because the fix that christhirst gave me unfortunately wont work. I am sorting the database alphabetically and want to output movie titles with The in the correct spot as if The wasnt in the name. For example, The Attack of Chrishirst would be sorted under 'A'.

So the code that was suggested would just remove anything with 'The' at the beginning from the search completely.

Anyways I know how to do it using php. Just output everything not containing 'The' to an array, and then the stuff containing 'the' strip the openening 'The', merge the two arrays and then sort them and then add "the" back onto the ones that had it before.

Ok so that would work, but before I do that is there a simple and efficient sql way to do that so I dont slow down the load speed of the page by having it do pointless work.

Thanks again.
Truly is offline
Reply With Quote
View Public Profile
 
Old 12-22-2007, 11:47 PM Re: Cancelling out 'The ' in a mysql query
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I found something that should work for you:

Code:
SELECT *
FROM table_name
ORDER BY REPLACE(UPPER(field_name), 'THE ', '');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 12-24-2007, 02:19 AM Re: Cancelling out 'The ' in a mysql query
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
I suggest you better to have two eparate fields in your table, one for original title with 'The' in the beginning, and the second for digested title, with 'The' at the end. This is to avoid calling functions on each query and thus increase performance.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 12-24-2007, 03:06 AM Re: Cancelling out 'The ' in a mysql query
Junior Talker

Posts: 1
Trades: 0
SQL isn't the best way with the "The" problem - write something to loop through the db table, taking the title, searching for initial 'The' by string comparison and then re-insert the title in the form "xxx xxx, The" - as above...
__________________

Please login or register to view this content. Registration is FREE
polyxena is offline
Reply With Quote
View Public Profile
 
Old 12-26-2007, 08:30 PM Re: Cancelling out 'The ' in a mysql query
Truly's Avatar
Ultra Talker

Posts: 322
Trades: 0
Yeh I might end up taking you advice on that mtishetsky. Otherwise I will just make a php script to search it.

Anyways thanks for the suggestions guys.
Truly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Cancelling out 'The ' in a mysql query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28419 seconds with 12 queries