X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fquery_commod;h=a5c8846491dee9006406bc7c7fb3c1e2573b47a6;hp=9cb14ca6870e70abf887b518f2e9698313d67158;hb=92ddda950c5bbbaf3dfcdc9ca41409ce248f43d5;hpb=beb534d7a087641ff404c3d36d81db61e9d6c05d
diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod
index 9cb14ca..a5c8846 100644
--- a/yarrg/web/query_commod
+++ b/yarrg/web/query_commod
@@ -37,6 +37,7 @@
$quri
$dbh
$commodstring => '';
+$prselector
$someresults
$emsgokorprint
%args>
@@ -48,7 +49,9 @@ my ($commodname,$commodid);
my $qa= \%ARGS;
%perl>
-
Select commodity
+Select commodity enquiry
+
+% $prselector->('BuySell');
%#---------- textbox, user enters route as string ----------
% if (!$qa->{Dropdowns}) {
@@ -77,10 +80,50 @@ Not yet implemented.
%#========== results ==========
-% $emsgokorprint->($emsg) or $commodid=undef;
+<%perl>
+
+$emsgokorprint->($emsg) or $commodid=undef;
+return unless defined $commodid;
+$someresults->();
+
+#---------- actually compute the results and print them ----------
+
+foreach my $bs (split /_/, $ARGS{BuySell}) {
+ $bs =~ m/^(buy|sell)$/ or die;
+ $bs= $1;
+
+ my $sth= $dbh->prepare(
+ "SELECT archipelago, islandname, stallname, price, qty
+ FROM $bs NATURAL JOIN stalls NATURAL JOIN islands
+ WHERE commodid = ?"
+ );
+ # fixme this query is utterly wrong
-% if (defined $commodid) {
-% $someresults->();
-COMMODITY <% $commodid %> named <% $commodname |h %>
+ $sth->execute($commodid);
-% }
+%perl>
+
+Offers to <% uc $bs |h %> <% $commodname |h %>
+
+
+
+Archipelago
+ | Island
+ | Best stall
+ | Best price
+ | Qty at best
+ |
+% my $row;
+% while ($row=$sth->fetchrow_hashref) {
+ <% $row->{'archipelago'} %>
+ | <% $row->{'islandname'} %>
+ | <% $row->{'stallname'} %>
+ | <% $row->{'price'} %>
+ | <% $row->{'qty'} %>
+ |
+% }
+
+
+<%perl>
+}
+%perl>