[ic] Advanced Sort Question
Caleb Phillips
interchange-users@icdevgroup.org
Thu Jan 23 18:17:00 2003
> I have a results page, from which I read in a variable called [cgi
> name=browse_cat], where you can select to re-sort results (in a drop-down
> list) by certain criteria such as "Price High-Low, Price Low-High..etc". You
> get the idea. Very Amazon-esq.
>
> What I'm hoping to do is have a second drop-down box that lists the
> different manufactures together with the number of matches found. E.g.
> Stellar (4), Le Creuset (15), All-Clad (19).
Provided I understand your question correctly, what I would do is: write
a user-tag that generates this drop-down box. In sparse pseudo:
sub{
my $ret = '';
@results = query("SELECT manufacturer, COUNT(*) AS count FROM
products GROUP BY manufacturer");
foreach (@results){
$ret .= "<option value ... $manufaturer($count)>\n";
}
return $ret;
}
In any case, I would try to conserve your database access and make it do
all the grunt work for you. I am making a large assumption that you are
using MySQL, but that should align with the assumption that your head is
screwed on straight ;P.
Good Luck.
> For those of you who are interested here is a copy of my first "sort-by"
> drop down list.
>
> <form action="[process]" method=post>
> <input type=hidden name=mv_todo value=return>
> <input type=hidden name=mv_nextpage value=@@MV_PAGE@@>
> <select name=sort_field onChange="this.form.submit()">
> <b>Sort Results By</b>
> <option value="" [selected name=sort_field value=""]>Sort
> By:
> <option value="Price Low to High" [selected name=sort_field
> value="price"]> Price (low-high)
> <option value="Price High to Low" [selected name=sort_field
> value="price"]> Price (high-low)
> <option value="Manufacturer A-Z" [selected name=sort_field
> value="manufacturer"]> Manufacturer (a-z)
> <option value="Manufacturer Z-A" [selected name=sort_field
> value="manufacturer"]> Manufacturer (z-a)
> </select>
> <input type=submit value="GO!">
> </form>
>
> John D
--
-------------------------------------------
| Caleb Phillips |
| The Studio Resource |
| IT Specialist |
| |
| Handcrafted for you in Ximian Evolution |
-------------------------------------------