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 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' ) 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%`; 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... 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 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. 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 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"); 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 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 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
Archived
This topic is now archived and is closed to further replies.