chiark / gitweb /
Commodity listing, but query is wrong
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Aug 2009 15:34:10 +0000 (16:34 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 16 Aug 2009 15:34:10 +0000 (16:34 +0100)
yarrg/web/query_commod

index 9cb14ca6870e70abf887b518f2e9698313d67158..a5c8846491dee9006406bc7c7fb3c1e2573b47a6 100644 (file)
@@ -37,6 +37,7 @@
 $quri
 $dbh
 $commodstring => '';
+$prselector
 $someresults
 $emsgokorprint
 </%args>
@@ -48,7 +49,9 @@ my ($commodname,$commodid);
 my $qa= \%ARGS;
 </%perl>
 
-<h1>Select commodity</h1>
+<h1>Select commodity enquiry</h1>
+
+% $prselector->('BuySell');
 
 %#---------- textbox, user enters route as string ----------
 % if (!$qa->{Dropdowns}) {
@@ -77,10 +80,50 @@ Not yet implemented.
 </form>
 
 %#========== 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>
+
+<h2>Offers to <% uc $bs |h %> <% $commodname |h %></h2>
+
+<table>
+<tr>
+<th>Archipelago
+<th>Island
+<th>Best stall
+<th>Best price
+<th>Qty at best
+</tr>
+%      my $row;
+%      while ($row=$sth->fetchrow_hashref) {
+<tr> <td><% $row->{'archipelago'} %>
+     <td><% $row->{'islandname'} %>
+     <td><% $row->{'stallname'} %>
+     <td><% $row->{'price'} %>
+     <td><% $row->{'qty'} %>
+</tr>
+%      }
+</table>
+
+<%perl>
+}
+</%perl>