
freddo
User
May 24, 2001, 7:25 PM
Post #14 of 21
(15976 views)
|
Hi again Manunkind, here's my try at your last question, i bet there will be some typos or bugs, but it´s 4:30am here, and i dont have apache, nor mysql around. So if it cores too much, tell me and i´ll get a look at it at home this w-e.#!/usr/bin/perl use CGI; use DBI; # next come an array of hashes, the order have its importance for the display # the hashes value are the following: # field: the name of the field used in both the form, and in you db # name: the english name for that field # check: the type of check you wish for that field, empty means no check # show: show the field in the result table ( 1/0 = yes/no ) @db_infos = ( { field => "member_id", name => "Member ID", check => '=', show => 0 }, { field => "first_name", name => "First Name", check => '', show => 1 }, { field => "last_name", name => "Last Name", check => '=', show => 1 }, { field => "title", name => "Title", check => '', show => 0 }, { field => "email", name => "Email Address", check => '', show => 0 }, { field => "dob", name => "Date of Birth", check => '=', show => 0 }, { field => "username", name => "Username", check => '=', show => 1 }, { field => "password", name => "Password", check => '', show => 0 }, { field => "business_name", name => "Business Name", check => '=', show => 0 }, { field => "mailing_street", name => "Mailing Street", check => '', show => 1 }, { field => "mailing_city", name => "Mailing City", check => '=', show => 1 }, { field => "mailing_state", name => "Mailing State", check => '=', show => 1 }, { field => "mailing_zip", name => "Mailing Zip", check => '=', show => 1 }, { field => "physical_street", name => "Physical Street", check => '', show => 0 }, { field => "physical_city", name => "Physical City", check => '=', show => 0 }, { field => "physical_state", name => "Physical State", check => '=', show => 0 }, { field => "physical_zip", name => "Physical Zip", check => '=', show => 0 }, { field => "phone", name => "Phone Number", check => '', show => 0 }, { field => "fax", name => "Fax Number", check => '', show => 0 }, { field => "url", name => "URL", check => '', show => 0 }, { field => "employees", name => "Employees", check => '', show => 0 }, { field => "business_type", name => "Business Type", check => '=', show => 0 }, { field => "description", name => "Business Description", check => '=', show => 0 }, { field => "membership_type", name => "Membership Type", check => '=', show => 0 }, { field => "dues", name => "Dues", check => '', show => 0 }, { field => "member_since", name => "Member Since", check => '=', show => 0 }, { field => "duration", name => "Duration", check => '=', show => 0 }, { field => "expiration", name => "Expiration Date", check => '=', show => 0 }, { field => "chapter", name => "Chapter", check => '=', show => 0 }, { field => "chapter_leader", name => "Chapter Leader", check => '=', show => 0 }, { field => "listed_directory", name => "Listed in Directory?", check => '=', show => 0 }, { field => "enhanced", name => "Enhanced Listing?", check => '=', show => 0 }, { field => "committees", name => "Committees", check => '=', show => 0 }, { field => "paid", name => "Paid?", check => '=', show => 0} ); # Creating the SQL statements: for (@db_infos) { $check = $query->param($_->{field}); push (@params, " ", $_->{field}, " ", $_->{check}, " '$check' ") if ( ($_->{check}) && ($check ne "") ); } $SQL = "select * from members\n where ".join(" and ", @params); # Fetching the results from mysql $dbh = DBI->connect("DBI:mysql:members", "<username>", "<password>") or die "Can not connect to the database"; $sth = $dbh->prepare($SQL); $sth->execute; $dbh->disconnect(); # i dont think fetchrow_hashref() needs a connection # print the http headers, top of page, and the table results print <<HTML; Content-type: text/html <html><head><title>Testing</title></head> <body><center><b>Your search has produced the following results:</b></center> <p> <table cellspacing="3" width="4500"> HTML # Print the headers on a row print "<tr>"; print "<td><b>", $_->{name}, "</b></td>" for (@db_infos); print "</tr>"; # Print found records, only the fields that we specified "show-able" while($ref = $sth->fetchrow_hashref()){ print "<tr>"; # new row print ($_->{show}?"<td>". $ref{$_->{field}} ."</td>":"") for (@db_infos); print "</tr>"; # next row } # End of table, and page print "</table></body></html>"; # This is the __END__ my only friend, the __END__ You may want to have a look to perldoc perldsc, the Perl Data Structures Cookbook. Note that for convenience i also attached the script to the message. I hope this helps, freddo ;--- Real programmers´butcher dont understand when they just ask for 3735928559.
|