Jump to content

Finding the number of arrays after explosion?


woolyg

Recommended Posts

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.

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

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.

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

 

 

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.