Cyto Posted December 5, 2011 Share Posted December 5, 2011 Hi, Is it possible to order by the first letter of name? Data is coming from a post value. $qorder = substr($q,0,1); SELECT * FROM data WHERE name LIKE '%$q%' OR info LIKE '%$q%' Want something like this: ORDER BY name='$qorder%', but doesnt work Thx, Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/ Share on other sites More sharing options...
Pandemikk Posted December 5, 2011 Share Posted December 5, 2011 ORDER BY ASC Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/#findComment-1294501 Share on other sites More sharing options...
sunfighter Posted December 5, 2011 Share Posted December 5, 2011 ORDER BY "column_name" [ASC, DESC] Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/#findComment-1294502 Share on other sites More sharing options...
Cyto Posted December 5, 2011 Author Share Posted December 5, 2011 I mean order by the value from post, so when the value is Santa. I want to order by S of Santa. Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/#findComment-1294738 Share on other sites More sharing options...
xyph Posted December 5, 2011 Share Posted December 5, 2011 SELECT `columns` FROM `table` WHERE `column` LIKE 's%' Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/#findComment-1294744 Share on other sites More sharing options...
Cyto Posted December 5, 2011 Author Share Posted December 5, 2011 SELECT `columns` FROM `table` WHERE `column` LIKE 's%' --- nvm --- Thx LIKE '$q%' works. Link to comment https://forums.phpfreaks.com/topic/252483-mysql-order-by-first-letter-of-name/#findComment-1294755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.