cgi ordering a table with sql

[email protected] ("Pat Rice")
Newsgroups perl.beginners
Message-ID <[email protected]>
hi all
I'm trying to achieve the following
a table that when I click on the top link I will chance the ORDER BY
value in the table. eg

|fruit 	| boxes |
|orange | 10	|
|apples	| 5	|

so if fruit was a link and I clicked it I would change my select
statement to order by fruit, if I clicked on boxes I would order by
boxes, if you get my idea, i'm trying to do this in one script.

Thanks in advance
Pat
	


  1 #!/usr/bin/perl
      2 use DBI;
      3 use strict;
      4 my $db = DBI->connect("dbi:SQLite:test.db", "", "",
      5 {RaiseError => 1, AutoCommit => 1});
      6
      7 #$db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)");
      8 #$db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')");
      9
     10
     11
     12
     13 #CREATE TABLE test1 (SR varchar(30), Account varchar(50),
Customer_Name varchar(50), Sev varchar(10), Status varchar(50),
Data_op        ened varchar(50), last_touched varchar(50), Next_Touch
varchar(50), Age varchar(10) , Last_touch varchar(10), sub_status
varchar(        50));
     14
     15
     16 my $all = $db->selectall_arrayref("SELECT * FROM test1 ORDER BY SR");
     17
     18
     19
     20 print "Content-Type: text/html\n\n";
     21
     22 print <<_HEADER_;
     23 <table>
     24 <tr>
     25   <th>SR<br>Number</th>
     26   <th>Quantity</th>
     27   <th>Shipped</th>
     28 </tr>
     29 _HEADER_
     30
     31
     32
     33
     34
     35 foreach my $row (@$all) {
     36
     37
     38 my ($TreeTest_Service_Request,$TreeTest_Account,
$TreeTest_Customer_Name,$TreeTest_Sev ,$TreeTest_Status
,$TreeTest_Date_Opened,$
TreeTest_Last_touched,$TreeTest_Next_Touch,$TreeTest_Age,$TreeTest_Last_Touch,$TreeTest_Sub_status)
= @$row;
     39
     40
     41
     42 print <<"_ROW_";
     43    <tr>
     44      <td>$TreeTest_Service_Request</td>
     45      <td>$TreeTest_Account</td>
     46      <td>$TreeTest_Customer_Name</td>
     47       <td>$TreeTest_Sev</td>
     48       <td>$TreeTest_Status</td>
     49       <td>$TreeTest_Date_Opened</td>
     50       <td>$TreeTest_Last_touched</td>
     51         <td>$TreeTest_Next_Touch</td>
     52         <td>$TreeTest_Age</td>
     53         <td>$TreeTest_Last_Touch</td>
     54         <td>$TreeTest_Sub_status</td>
     55
     56
     57
     58
     59    </tr>
     60 _ROW_
     61
     62
     63
     64 # print "\n$TreeTest_Service_Request, $TreeTest_Account,
$TreeTest_Customer_Name, $TreeTest_Sev , $TreeTest_Status
,$TreeTest_Dat        e_Opened, $TreeTest_Last_touched,
$TreeTest_Next_Touch, $TreeTest_Age, $TreeTest_Last_Touch,
$TreeTest_Sub_status";
     65
     66 print "\n";
     67 }
     68
     69
     70
     71
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.