[ic] Sorting

Mike Heins interchange-users@lists.akopia.com
Mon Jul 23 19:51:02 2001


Quoting Jim Balcom (jim@idk-enterprises.com):
> In my option for new items I have this search criteria:
> 
> fi=merchandising
> sf=featured
> se=new
> tf=sku
> 
> It works nice.
> 
> However, I want to sort the output by category, which is not in the
> merchandising file. It IS, however, in the products file.
> 
> How do I do this?

You can rely on the hoary old:

	[sort products:category]

inside your list. It is not the preferred method of sorting, but the
only current thing which does what you want. It will not sort spanning
pages of a more-list, though. Works well for small lists.

Another way is to turn the search around a bit:

[loop search="
        fi=products
        co=yes
        sd=
        st=db

        sf=category
        se=.
        su=1
        op=rm
        ac=0

        sf=merchandising:featured
        se=new
        op=rm
        su=0

        tf=category

    "][loop-code]: [loop-field category]<BR>
[/loop]

	

That would not be good for large products databases, but would work
well enough on a small one.

Finally, for larger tables you could use a SQL query and a real SQL database:

[query  list=1
	sql="SELECT m.sku, p.category FROM products AS p, merchandising AS m
		WHERE m.featured = 'new'
		AND p.sku = m.sku
		ORDER BY p.category"]
[sql-code] - [sql-param category]<br>
[/query]

-- 
Red Hat, Inc., 3005 Nichols Rd., Hamilton, OH  45013
phone +1.513.523.7621      <mheins@redhat.com>

"Even if you're on the right track, you'll get run over if you just
sit there." -- Will Rogers