nashsaint Posted May 4, 2008 Share Posted May 4, 2008 Hi, Here's my SQL Table named 'Disks' disk_id model_no job_no 'model_no' contains characters like HTSxxxxx, STxxxxx, 2Fxxxxx...etc.. What I want to do is to select model_no and truncate it in PHP so that i will only get the first 2 or 3 characters from the SQL query. And then group the result into separate categories (i.e., HTSxxxxxx to Hitachi category, STxxxx to Seagate Category... etc.). Is there anyone who can guide me how to do this? It would be of great help. Many thanks. Link to comment https://forums.phpfreaks.com/topic/104105-select-first-2-letters-from-sql-table/ Share on other sites More sharing options...
rarebit Posted May 4, 2008 Share Posted May 4, 2008 SELECT LEFT(model_no, 2) as model_no FROM ... etc is this what you mean? Link to comment https://forums.phpfreaks.com/topic/104105-select-first-2-letters-from-sql-table/#findComment-532977 Share on other sites More sharing options...
Bauer418 Posted May 4, 2008 Share Posted May 4, 2008 You'll want some sort of separation such as placing a hyphen between the manufacturer's 2/3 character code and the model #, so your items would be HTS-xxxxxx and ST-xxxxxx Then you can run something like: SELECT SUBSTRING_INDEX(model_no, '-', 1) as mft_code FROM Disks Link to comment https://forums.phpfreaks.com/topic/104105-select-first-2-letters-from-sql-table/#findComment-532990 Share on other sites More sharing options...
nashsaint Posted May 5, 2008 Author Share Posted May 5, 2008 Thanks guys, I ran the code and it gave me the result: mft_code SP IB WD SV MP 6K ST 6V HT FA HD MH MH MH ST ST WD HT ST HT WD .... How can I categorise them into different groups? Like MH to Toshiba Group, ST to Seagate... etc... It dont matter if its SQL or PHP as long as I am able to group them. Thanks guys for your help. Link to comment https://forums.phpfreaks.com/topic/104105-select-first-2-letters-from-sql-table/#findComment-533286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.