Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.