how can I do something like this?
$result = mysql_query( "SELECT * FROM wallpaper_cats WHERE sub_cat FirstLetterA" );//
selecting from mySQL database first letter
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
interesting. maybe try
or whatever. That is off the top of my head as what might work but odds are it does not. worth a shot though
Code: Select all
$sql = ......'WHERE thing = "'.$looking_for_letter.'"* LIMIT 20';I believe MySql's string function LEFT() is what you're looking for.
http://dev.mysql.com/doc/refman/5.0/en/ ... #id3219420
http://dev.mysql.com/doc/refman/5.0/en/ ... #id3219420
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Are you trying to truncate the first letter of a know data value down to it's first letter and match that? If so, use the MySQL LEFT() function...
EDIT | Darnit Hawley, you beat me to the punch. 
Code: Select all
<?php
$sql = "SELECT LEFT(`fieldname`, 1) AS first_letter FROM tablename WHERE first_letter = 'A')";
?>You will not be able to use the alias in the conditional statement.Everah wrote:Are you trying to truncate the first letter of a know data value down to it's first letter and match that? If so, use the MySQL LEFT() function...
EDIT | Darnit Hawley, you beat me to the punch.Code: Select all
<?php $sql = "SELECT LEFT(`fieldname`, 1) AS first_letter FROM tablename WHERE first_letter = 'A')"; ?>
Code: Select all
<?php
$sql = "SELECT LEFT(`fieldname`, 1) AS first_letter FROM tablename WHERE LEFT(`fieldname`, 1) = 'A')";
?>Re: selecting from mySQL database first letter
Code: Select all
SELECT blah
FROM wallpaper_cats
WHERE sub_cat LIKE 'A%'
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA