i mean i have songs table ok?? i want to make some things like that a | b | c | d click on a select from the database the songs that start by a Character how i can do that by the mysql???
+3
A:
I believe you can use a LIKE statement to achieve this.
SELECT * FROM `table` WHERE `title` LIKE 'a%'
That will select anything where the title starts with an 'a', the % allows for anything after that. I'm not sure if this is case-sensitive or not (I don't believe it is), can someone confirm either way?
animuson
2010-06-11 16:37:44
A:
Here it is in Python because I can't be bothered to look up the crappy PHP syntax:
qry = "select song_name from songs where left(song_name, 1) = '%s'" % letter
This assumes that you haven't foolishly used a case sensitive collation as well. In case you were being silly and did that well:
qry = "select song_name from songs where left(lower(song_name), 1) = '%s'" %
letter.lower()
Khorkrak
2010-06-11 16:38:39
Right. Because string assignment in PHP is just **so** insane looking. Uh huh.
webbiedave
2010-06-11 16:42:30
Really? All he even needs is the MySQL query line, I'm sure he can figure out how to use that in PHP.
animuson
2010-06-11 16:43:22
Yep as you can see from the OP the bar to entry for PHP is rather low. And those stupid $ symbols everywhere are irksome.
Khorkrak
2010-06-11 16:44:13
Quick suggestion about readability, SQL is less irksome to scan when you capitalize keywords/functions, i.e., `SELECT troll FROM comments WHERE username = 'you'`
webbiedave
2010-06-11 16:53:53
Uppercase is for IBM mainframe programmers. It just looks like the code yelling at you and feels rather unnecessary - especially since there's a nice sql mode in Emacs that color codes your sql instead.
Khorkrak
2010-06-11 17:17:20
Interesting. Thanks for *removing all doubt*.
webbiedave
2010-06-11 17:43:25
+1
A:
Retrieved from: http://www.webmasterworld.com/forum88/2320.htm
select * FROM `table` WHERE LEFT(`value`, 1) NOT BETWEEN 'A' AND 'Z'
Joseph
2010-06-11 17:00:37