papaface Posted June 5, 2007 Share Posted June 5, 2007 Hello, How can I select a record or records from a database by the first letter of the "title" field? e.g I want to find all titles that begin with the letter L regards Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/ Share on other sites More sharing options...
redarrow Posted June 5, 2007 Share Posted June 5, 2007 try this ok SELECT * FROM table ORDER BY FIELD( field_name, 'L' ) Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-267976 Share on other sites More sharing options...
saf Posted June 5, 2007 Share Posted June 5, 2007 Try this: SELECT * FROM `database` WHERE `title` LIKE `L%`; Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-267977 Share on other sites More sharing options...
papaface Posted June 5, 2007 Author Share Posted June 5, 2007 I tried: mysql_query("SELECT * FROM videos WHERE title LIKE `".mysql_real_escape_string($_GET['l'])."%` ORDER BY title ASC"); $_GET['l'] is M But it doesnt work... Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268007 Share on other sites More sharing options...
papaface Posted June 5, 2007 Author Share Posted June 5, 2007 oops it did. But I got this error when I changed it slightly to: mysql_query("SELECT * FROM videos WHERE category='".$category."' AND title LIKE `".mysql_real_escape_string($_GET['l'])."%` ORDER BY title ASC"); error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268012 Share on other sites More sharing options...
dough boy Posted June 5, 2007 Share Posted June 5, 2007 Not sure but it doesn't appear the ' around the mysql_real_escape_string function are the correct 's; You should also echo the sql and try running it manually in the database to see what the error is. Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268019 Share on other sites More sharing options...
papaface Posted June 5, 2007 Author Share Posted June 5, 2007 I tried: mysql_query("SELECT * FROM videos WHERE category='".$category."' `title` LIKE '".mysql_real_escape_string($_GET['l'])."%' ORDER BY title ASC"); still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268024 Share on other sites More sharing options...
redarrow Posted June 5, 2007 Share Posted June 5, 2007 $x=mysql_real_escape_string($_GET['l']); mysql_query("SELECT * FROM videos WHERE category='".$category."' `title` LIKE '".$x."%' ORDER BY title ASC"); Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268026 Share on other sites More sharing options...
papaface Posted June 5, 2007 Author Share Posted June 5, 2007 Got it working. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268029 Share on other sites More sharing options...
redarrow Posted June 5, 2007 Share Posted June 5, 2007 post ur result for us all and press solved lol Quote Link to comment https://forums.phpfreaks.com/topic/54200-solved-select-something-if-the-first-character-is-x/#findComment-268032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.