开发者

How can I filter the records from an SQLite database in my Perl CGI script?

Here is the table in which ia am retrieving the data from sqlite,, at the top of this datagrid i need a fil开发者_如何学Pythonter button and 2 text boxes..1 for userId and 1 for userName...All i need is tha as a enter the userid and username the record confined to tha id or name should appear ...Please do help me..am newbie to perl...

#!C:\perl\bin\perl.exe

use CGI;
use CGI qw/:standard/;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my $q = new CGI;
use DBI;
use CGI qw(:all);
use warnings;
print $q->header ( );
my $dbh = DBI->connect(
        "dbi:SQLite:DEVICE.db",
        "", "",
        {
            RaiseError => 1,
            AutoCommit => 1
        }
    );
 my @rows = ();
 my $sql = "SELECT UserId,UserName,CardNo,GroupId,Role,VerifyType FROM UsersList";
 my $sth = $dbh->prepare($sql) or die("\n\nPREPARE ERROR:\n\n$DBI::errstr");
  $sth->execute or die("\n\nQUERY ERROR:\n\n$DBI::errstr");
 print '<table>';
 print "<tr>";
 print "<th>$sth->{NAME}->[0]</th>";
 print "<th>$sth->{NAME}->[1]</th>";
 print "<th>$sth->{NAME}->[2]</th>";
 print "<th>$sth->{NAME}->[3]</th>";
 print "<th>$sth->{NAME}->[4]</th>";
 print "<th>$sth->{NAME}->[5]</th>";
 print "<th>  EDIT  </th>";
 print "<th>  DELETE  </th>";

 while (my @row = $sth->fetchrow_array) {
  print "
 <tr>
 <td>$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
 <td>$row[3]</td>
 <td>$row[4]</td>
  <td>$row[5]</td>
  <td><A HREF=\"\">EDIT</A></td>
  <td><A HREF=\"\">DELETE</A></td>
   </tr>";
   }
   print "<tr style='background-color:#CDC9C9;'><td><A HREF=\"http://localhost/cgi- 
     bin/AddUser.cgi\">ADD</A></td><td></td><td></td><td></td><td></td></tr>";
   print"</table>";
   $sth->finish();
     $dbh->commit();
  $dbh->disconnect;


 print <<END_HTML;
 <html>
 <head><title></title></head>
 <body>
  <form action="UsersList.cgi" method="get">
 <TABLE align="center">

  <TR>
  <TD align="left">
 <input type="hidden" name="submit" value="Submit">

</TD>
</TR>
  </TABLE>

  </form>
   </body></html>
    END_HTML


You can filter the records that are returned by added a 'where' clause to your SQL statement. You can get the parameters that have been typed into your text boxes by using the 'param' function from CGI.pm.

You say that you want to filter the results as text is typed into the text boxes. That is harder. You would need to use Javascript and Ajax to do that.

You seem to be a little confused about CGI and Perl. You are, for example, loading the CGI module three times and then only using one of its functions. I strongly recommend that you read something that will help you understand the underlying concepts before writing any more code. Ovid's CGI course is a great introduction.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜