Forum Moderators: coopster
what you need is LIKE
select columnname from table where columnname LIKE 'A%';
you use like instead of = to use a match. The % can represent any number of characters. You can also use * which represents a single char
[dev.mysql.com...]
I am not sure why the results are displaying as you have posted but in my opinion if you would like to collect the first letter if the word then why don't you use the substring function?
---------------------------------------------------------
select * from table where SUBSTRING(columnname, 1, 1) = 'a';
For your info: SUBSTRING(columnname, offset (starts from 1), length);
---------------------------------------------------------
This way you would always be comparing the first letter and not any other characters in the request string.
I hope this helps, good luck!
Del
how would i have it exclue the letter "a" and word "the" when running that select statement?
You'll probably want to add another Replace to take care of titles starting with "An" as well.
A more efficient option would be to make a second column with A, An, and The already stripped out of the title and search on that column (instead of having to do the replaces every time you search).
[edited by: LifeinAsia at 12:15 am (utc) on Jan. 16, 2007]
I have a database of movies a movie review website,
The Movies in the DB are:
Alien Versus Preditor
The Aviator
A City of Angels
Anger Management
My sql query is setup like this:
mysql_query("SELECT * FROM reviews WHERE Title LIKE '$a%'",$db); It Outputs right.... Which would be this:
Alien versus Preditor
A City of Angels
Anger Management
It outputs everything thats starts with a, I want it to output every thing that starts with a, but if it has a single "a" or the word "the" before it, and the next word starts with "a", it will output that too. So in the example it would also output "The Aviator", but it wouldnt output "A City of Angels".
The Final output id be hoping for would be:
Alien Versus Preditor
The Aviator
Anger Management
Thanks,
Greg
Alien Versus Preditor
Aviator, The
City of Angels, A
Anger Management
Then search will perform fine, and in the display you can do:
$explode = explode(", ", $title);
if(in_array($explode[1], array("A", "An", "The"))) $title = $explode[1]." ".$explode[0];
However it won't find directly input A City of Angels
Hope this helps you in some way.
Michal