Monkuar Posted May 8, 2012 Share Posted May 8, 2012 Here is my query SELECT id,username,star,color,actions from users WHERE actions >= 1 ORDER BY actions DESC actions field value is "213|1336456267" how can I use mysql to explode so it only reads the first literation of the exploded values, like 213? Is this why people always say you shouldn't store exploded variables? Theres gotta be a way tho right? in other words; is there a mysql function that exploded that actions variable in the query with a | to read only the "213" ? Quote Link to comment https://forums.phpfreaks.com/topic/262241-explode-it-inside-a-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2012 Share Posted May 8, 2012 http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_substring-index Quote Link to comment https://forums.phpfreaks.com/topic/262241-explode-it-inside-a-query/#findComment-1343885 Share on other sites More sharing options...
Monkuar Posted May 8, 2012 Author Share Posted May 8, 2012 http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_substring-index I dont understand the syntax mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2); -> 'www.mysql' is www.mysql.com supposed to represent the field name or? so something like this: SELECT SUBSTRING_INDEX('actions', '|', 2); ? Quote Link to comment https://forums.phpfreaks.com/topic/262241-explode-it-inside-a-query/#findComment-1343889 Share on other sites More sharing options...
Monkuar Posted May 8, 2012 Author Share Posted May 8, 2012 $db->query('SELECT id,username,star,color,actions from users WHERE actions >= 1 ORDER BY SUBSTRING_INDEX(\'actions\', \'|\', 2) DESC') WOW TOPIC SOLVED!!! Didn't know you could do this, wow I can store alot of information in explodes now and call them. AwesomE! Quote Link to comment https://forums.phpfreaks.com/topic/262241-explode-it-inside-a-query/#findComment-1343891 Share on other sites More sharing options...
xyph Posted May 8, 2012 Share Posted May 8, 2012 You should only store information in explodes (delimited information) when you don't want to query specific values in that data. You're greatly slowing down your query by using SUBSTRING_INDEX Quote Link to comment https://forums.phpfreaks.com/topic/262241-explode-it-inside-a-query/#findComment-1343990 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.