arrays

iclbloom
Posts: 103
Joined: Mon May 07, 2001 5:51 pm

arrays

Post by iclbloom »

<SCRIPT LANGUAGE=vortex>

<a name=main public>
<$addr = www.leon.com www.xyz.leon.com www.john.com www.abc.john.com www.test.abc.leon.com>

<loop $addr>
<split "\." $addr><$addr_s = $ret>
<loop $addr_s>
$addr_s<br>
</loop>
<br>
</loop>
</a>

</script>
<!--- end script --->

I'd like to get just the last three 'parts' of the url in $addr,
i.e.,
www leon com
xyz leon com
www john com
abc john com
abc leon com

What I'd like to do is simply read the parts into an
array and get the length of the array and return the len, len -1, len -2 items
of the array for each value. how can I do this in vortex. Are there
arrays w/ referenceable items?

Thanks
Leon Bloom
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

arrays

Post by Kai »

If you want the last 3 parts contiguously (ie. one value), then REX is easiest:

<rex "[^.]+\.=[^.]+\.=[^.]+>>=" $addr>

This would give www.leon.com, xyz.leon.com etc.

If you want the last 3 parts individually, you can use the REV flag to <LOOP>. Just change your <loop $addr_s> to <loop REV MAX=3 $addr_s>, and you'll get the last 3 values, in reverse order. (<count $array> will return the number of elements in the array, but it's not needed in this case if I understand what you want to do.)

(This also assumes a Vortex version of Jan 2000 or later for REV.)
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

arrays

Post by mark »

You could use count and loop with max and skip to get the array members. For your case though I would simply rex the addr's down to the last 3 parts.

<rex "[^.]+\.=[^.]+\.=[^.]+>>=" $addr>
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

arrays

Post by josmani »

What is the best way to create a multi-column array?

ie getting the following set of data in an array.

apples 14
oranges 20
mangoes 34

I've tried:

<$myArray['apples'] = 14>

and got "Missing start single quote in value" error.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

arrays

Post by John »

That depends exactly what you are trying to do, but a database table maybe the best option.
John Turnbull
Thunderstone Software
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

arrays

Post by josmani »

The data set I have is already in a tables. To present them the way I want, I have to join tables which has slowed down the performance. So I was thinking of arrays the do the job.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

arrays

Post by mark »

Try describing what you're really trying to accomplish with your data. Maybe we can suggest a good solution.
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

arrays

Post by josmani »

Let's say I have the following two tables.

RECORDS
=======
ID
TITLE
PUBLISHERID

PUBLISHERS
==========
PUBLISHERID
PUBLISHERNAME

The RECORDS table has around 90000 records. I need to group the number records by publisher, displaying and sorting by PUBLISHERNAME.

A query joining the two tables (with proper indeces) will take around 60 seconds to run. I am looking for a way to speed up performance.


PS. I still like to know your idea on No4.
User avatar
John
Site Admin
Posts: 2622
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

arrays

Post by John »

For you case it may be best to nest SQL statements, e.g.

<SQL ROW "select PUBLISHERID, count(*) N from RECORDS group by PUBLISHERID">
<SQL "select PUBLISHERNAME from PUBLISHERS where PUBLISHERID = $PUBLISHERID">
$PUBLISHERNAME - $N
</SQL>
</SQL>

For multiple column array you would use two variables:

<$var1=apples oranges mangoes>
<$var2=14 20 34>
John Turnbull
Thunderstone Software
josmani
Posts: 53
Joined: Tue Jun 03, 2003 3:38 am

arrays

Post by josmani »

Thanks for the quick reply.

I've aready tried this method, the issue of being able to sort by PUBLISHERNAME is still there.

Same with the multiple column array you mentioned. If I sort the first array the second would not sort accordingly.
Post Reply