woolyg Posted October 2, 2007 Share Posted October 2, 2007 Hi, If I have data I wish to explode, say $text = 'hi, there, everyone, ..., .., ......'; $arr = explode(", ",$text) How do I find out how many items are in the exploded array, if I do not know how many items are in the imploded $text variable? All help appreciated, Woolyg. Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/ Share on other sites More sharing options...
clearstatcache Posted October 2, 2007 Share Posted October 2, 2007 $num = count($arr); Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359843 Share on other sites More sharing options...
woolyg Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks for that. Now, if I wanted to create a mysql query that ordered the results based on the number of items in a field, is this possible? Something along the lines of this (I know it's wrong, but...) SELECT * FROM table ORDER BY count(explode(", ",table.text)) DESC LIMIT 1 - Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359858 Share on other sites More sharing options...
woolyg Posted October 2, 2007 Author Share Posted October 2, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359875 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 i'm not 100% sure what your asking but i assume you want this <?php $text = 'hi, there, everyone, ..., .., ......'; $arr = explode(", ",$text) $Total = count($arr); $SQL = "SELECT * FROM table ORDER BY $Total DESC LIMIT 1"; ?> BUT this will probably fail.., as $Total should be a field name.. not a number! i have no idea what your trying to do please explain what you want the end result to be. Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359878 Share on other sites More sharing options...
woolyg Posted October 2, 2007 Author Share Posted October 2, 2007 Say if the info in a field is delimited by a comma, I want to find a way to count the commas. Something like this text_field --------- hello,my,name,is,woolyg, SELECT COUNT(REPLACE(text_field,' ','')) AS number from table If I can count the commas between the text, I can order the full table results by it... so you get me? - Woolyg Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359882 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 I can order the full table results by it... so you get me? Erm.. what! you can not order by a number you need to order by a field... as for the count, the php count and mysql count are NOT the same.. i still have no idea what your trying to do! Quote Link to comment https://forums.phpfreaks.com/topic/71484-finding-the-number-of-arrays-after-explosion/#findComment-359886 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.