Manipulating arrays and mySQL query results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CobraCards
Forum Newbie
Posts: 13
Joined: Fri Feb 03, 2006 1:40 pm

Manipulating arrays and mySQL query results

Post 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!
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply