jaacmmason has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance for any help I may receive on how to add buttons after each displayed line of data from the query results.#!perl use DBI; use CGI; print "Content-Type: text/html\n\n"; $head = <<'HEAD'; <html> <head> <title>Branch Inventory Lookup</title> </head> <body style="font-size:11px;font-family:tahoma;background:#F9F9DD;padd +ing:0;margin:0;"> HEAD $tail = <<'TAIL'; </body> </html> TAIL $body = <<'BODY'; <div style="padding-left:20px;padding-top:10px;background:#F9F9DD;"><h +1><font color="#006600"> Branch Inventory Query</font></h1>div> <div style="font-size:18px;letter-spacing:5px;padding-top:15px;text-al +ign:center;background:#F9F9DD;width:100%;"> <form action="http://hmDir/cgi-bin/Inventory.pl" method="get"> <select style="font-size:15px;" name="field"> <option value="Branch">Branch</option> <option value="AssetTag">Asset Tag</option> <option value="SerialNumber">Serial Number</option> <option value="Status">Status</option> <option value="AssetType">Asset Type</option> </select> <select name="likeEquals" style="font-size:15px;"> <option value="=">=</option> <option value="LIKE">LIKE</option> </select> <input style="font-size:15px;" type="text" name="searchTerm"/> <input style="font-size:15px;" type="submit" name="search" value=" +Search"/> </form> </div> <div style="font-size:18px;letter-spacing:5px;padding-top:15px;padding +-right:20px;text-align:right;background:#F9F9DD;width:100%;"> <form method="get"> <input type="button" value="Print" onclick="window.print()" /> </form> </div> BODY $results = <<'RESULTS'; <div style="padding:5px;position:absolute;top:275px;height:100px;width +:100%;background:#F9F9DD;"> <table cellspacing="0" cellpadding="3" style="padding:5px;font-size:11 +px;border:1px black solid;" bgcolor="#EEEEEE" width="100%"> RESULTS $i = 0; $c = new CGI(); $searchTerm = $c->param("searchTerm"); $likeEquals = $c->param("likeEquals"); $field = $c->param("field"); $searchTerm =~ s/'/\\'/; $likeEquals =~ s/'/\\'/; $field =~ s/'/\\'/; if($searchTerm eq "") { $searchTerm = "void"; } $h = DBI->connect("dbi:mysql:inventory:localhost","ID","PW") or die("c +ouldnt connect to database"); $query = "SELECT SerialNumber, AssetTag, AssetType, Branch, Status, Co +mments FROM assets WHERE $field $likeEquals ? ORDER BY AssetType"; $q = $h->prepare($query); $rows = $q->execute($searchTerm); %columns = ( SerialNumber => "Serial Number", AssetTag => "Asset Tag", AssetType => "Asset Type", Branch => "Branch", Status => "Status", Comments => "Comments", ); if($rows > 0) { $results .= "<tr><td colspan='6'>Your search for <b>$searchTerm</b> in + <b>$columns{$field}</b> returned <b>$rows</b> result(s).</td></tr>"; $results .= "<tr style='background:black;color:white;font-weight:900;' +>"; foreach $field (@{$q->{NAME}}) { $results .= "<td width='50'>$columns{$field}</td>"; } $results .= "</tr>"; if($c->param("searchTerm")) { while ($row = $q->fetchrow_hashref) { if($i % 2 == 0) { $results .= "<tr style='height:30px;border-bottom:1px;'><t +d>$row->{SerialNumber}</td><td>$row->{AssetTag}</td><td>$row->{AssetT +ype}</td><td>$row->{Branch}</td><td>$row->{Status}</td><td>$row->{Com +ments}</td></tr>"; } else { $results .= "<tr style='height:30px;border-bottom:1px;back +ground:#DDD;'><td>$row->{SerialNumber}</td><td>$row->{AssetTag}</td>< +td>$row->{AssetType}</td><td>$row->{Branch}</td><td>$row->{Status}</t +d><td>$row->{Comments}</td></tr>"; } $i++; } } } else { $results .= "<b>No results matched your Inventory query.</b>"; } $h->disconnect(); $results .= <<'RESULTS'; </table> </div> RESULTS print $head; print $body; print $results; print $tail;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding command button to selevt a value
by poj (Abbot) on Feb 11, 2011 at 15:42 UTC | |
by jaacmmason (Acolyte) on Feb 21, 2011 at 19:11 UTC |