Split then Sort

Post Reply
wdavies
Posts: 19
Joined: Mon Dec 17, 2001 5:15 pm

Split then Sort

Post by wdavies »

So I can't get this to work...

It just prints out the first item of the list.
SearchPhrase should contain
"blue yellow red"
and I want it to return
the list

"blue" "red " "yellow"

Cheers,
Winton

<sql $sqlcommand>
START: $SEARCHPHRASE
<split " " $SEARCHPHRASE>
<$SEARCHPHRASE = $ret >
<sort $SEARCHPHRASE>
<$SEARCHPHRASE = $ret >
<LOOP $SEARCHPHRASE>
$SEARCHPHRASE
</LOOP>
END
</sql>
wdavies
Posts: 19
Joined: Mon Dec 17, 2001 5:15 pm

Split then Sort

Post by wdavies »

Oh well this seems to work. Go figure :)

<split " " $SEARCHPHRASE>
<sort $ret>
<split ROW " " $ret>
$ret
</split>
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Split then Sort

Post by mark »

There could be an issue if SEARCHPHRASE is one of the fields selected in your sql statement. If so, use some other variable name after splitting it.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Split then Sort

Post by John »

Assuming that $SEARCHPHRASE came from your SQL statement you are looping over the results, building up the array $SEARCHPHRASE, so you can only see a single element of the $SEARCHPHRASE array. Your much shorter and simpler form avoided reassigning a list to a single element of $SEARCHPHRASE.

You might also want <sql ROW> to avoid keeping all the results in memory.
John Turnbull
Thunderstone Software
Post Reply