The problem with "the"

A while back, I was working with a list of companies being displayed on a client's site, and I ran into an obvious issue. Some businesses' names begin with the word "the". Their names are in the MySQL database with the word "the" already in the business name column. I need to sort the business names alphabetically, but I don't want the "Ts" to be populated with all the "the's". Those businesses need to be sorted by the first letter after the "the". I have read that some people like to actually insert the word "the" into a separate column, then sort by the business name and then rebuild the two columns after the fact. These steps seem to be a bit cumbersome, as one would need to check the name upon insertion and split the name if "the" exists, then always build the name again after sorting in the "select" statement. Here is a simple way to use the database to do this sorting for you while reducing your code upon insert and also eliminates the need to check the extra column for "the" while displaying the page
mysql_query( "SELECT * FROM your_table_name ORDER BY TRIM(LEADING 'the ' FROM LOWER( businessname ))" )
this will order names on your output page like this... ABC Business, Inc. The Best Business Busy Business It removes "the" from the sorting and allows you to have the full business name in one column.
Post a comment

Real Time Web Analytics ^