Page 1 of 1

Manipulating arrays and mySQL query results

Posted: Tue Feb 07, 2006 6:53 pm
by CobraCards
I need to fetch the contents (text stings) of a mySQL database table, stripping the tags from each text string, and putting them in order of descending length.

For example, if my database contains:
XXXXX
<b>YYYY</b>
ZZZZZZZZZ

Then I would get this array:
ZZZZZZZZZ
XXXXX
YYYY


The code I'm using now includes the length bit in the mySQL query ("ORDER BY LENGTH(whatever) DESC"), and then strips the tags, but I need this to happen the other way around so that the length calculation doesn't include the tags!

I'm hoping there is some way to basically do "ORDER BY LENGTH(strip_tags(whatever)) DESC" in the mySQL query, because otherwise I have to actually deal with manipulating/rearranging the array, and that's way out of my experience. :lol:

Any help is much appreciated!

Posted: Tue Feb 07, 2006 7:04 pm
by nickman013

Posted: Tue Feb 07, 2006 7:21 pm
by feyd
unfortunately, this can't really be done easily within just MySQL. You'll need to run a normal selection, then strip tags from each record, and finally use usort() with a function you create that uses strlen() to determine ordering.