ballouta Posted June 12, 2009 Share Posted June 12, 2009 Hello This is the begining of a code that displays the first letter of members in a table... <?php $query = "SELECT SUBSTRING(`usernme`,1,1) as letter FROM `members` GROUP BY letter"; ?> Actually this code is working fine BUT now i need to query all members names beining with a speicific letter/number. For example, If i press on letter m, i want to display all members names begiging with letter m. Please help Thank You Link to comment https://forums.phpfreaks.com/topic/161996-solved-query-help/ Share on other sites More sharing options...
Ken2k7 Posted June 12, 2009 Share Posted June 12, 2009 SELECT username FROM members WHERE username LIKE 'someletter%'; The someletter part can be a PHP variable. Link to comment https://forums.phpfreaks.com/topic/161996-solved-query-help/#findComment-854748 Share on other sites More sharing options...
ldougherty Posted June 13, 2009 Share Posted June 13, 2009 Why not just add a WHERE statement to the query. <?php $query = "SELECT SUBSTRING(`usernme`,1,1) as letter FROM `members` WHERE letter = 'm'"; ?> Link to comment https://forums.phpfreaks.com/topic/161996-solved-query-help/#findComment-854850 Share on other sites More sharing options...
Ken2k7 Posted June 13, 2009 Share Posted June 13, 2009 Because letter is not a known column. Link to comment https://forums.phpfreaks.com/topic/161996-solved-query-help/#findComment-854866 Share on other sites More sharing options...
ballouta Posted June 13, 2009 Author Share Posted June 13, 2009 Thanks Ken2k7, ur code is working. ldougherty query is not working because the letter is not a column Thank you all Link to comment https://forums.phpfreaks.com/topic/161996-solved-query-help/#findComment-854893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.