dflow Posted April 13, 2011 Share Posted April 13, 2011 for example: ID=35 ID=105 Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/ Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2011 Share Posted April 13, 2011 RIGHT() SELECT `id` FROM `table` WHERE RIGHT(`id`, 1) = 5 Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201112 Share on other sites More sharing options...
dflow Posted April 13, 2011 Author Share Posted April 13, 2011 RIGHT() SELECT `id` FROM `table` WHERE RIGHT(`id`, 1) = 5 thanks Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201113 Share on other sites More sharing options...
dflow Posted April 13, 2011 Author Share Posted April 13, 2011 ok it works in the phpmyadmin but when i intergrate it with : SELECT * FROM apartments WHERE InternalSupplierID ='1' AND country_id = '20' AND city_id = '2' and Desc <>'' and RIGHT( 'ID',1 ) =5 i get empty results although i see results without " RIGHT( 'ID',1 ) =5" in the query that should match Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201144 Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2011 Share Posted April 13, 2011 You're using single quotes around 'id'. Those should either be replaced with `backticks` or simply removed. Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201145 Share on other sites More sharing options...
dflow Posted April 13, 2011 Author Share Posted April 13, 2011 ok it works in the phpmyadmin but when i intergrate it with : SELECT * FROM apartments WHERE InternalSupplierID ='1' AND country_id = '20' AND city_id = '2' and Desc <>'' and RIGHT( 'ID',1 ) =5 i get empty results although i see results without " RIGHT( 'ID',1 ) =5" in the query that should match You're using single quotes around 'id'. Those should either be replaced with `backticks` or simply removed. cheers again Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201148 Share on other sites More sharing options...
Pikachu2000 Posted April 13, 2011 Share Posted April 13, 2011 desc is a MySQL reserved word. Either enclose it in `backticks`, or rename the column. You should be checking for query failure, and using mysql_error() while developing . . . Quote Link to comment https://forums.phpfreaks.com/topic/233602-how-to-query-ids-ending-with-5-in-the-ones-digit/#findComment-1201153 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.