Database Reference
In-Depth Information
{
$link = $label ;
}
$page .= "[$link] " ;
}
20.11. Generating “Click to Sort” Table Headings
Problem
You want to display a query result in a web page as a table that enables the user to select
the column by which to sort the table rows.
Solution
Make each column heading a hyperlink that redisplays the table, sorted by the corre‐
sponding column.
Discussion
A web script can determine what action to take by examining its environment to find
out what parameters are present and what their values are. In many cases these param‐
eters come from a user, but there's no reason a script cannot add parameters to URLs
itself. This is one way a given invocation of a script can send information to the next
invocation. The effect is that the script communicates with itself by means of URLs that
it generates to cause specific actions. An application of this technique is for showing the
result of a query such that a user can select which column of the result to use for sorting
the display. To do this, make the column headers active links that redisplay the table,
sorted by the selected column.
The examples here use the driver_log table, which has these contents:
mysql> SELECT * FROM driver_log;
+--------+-------+------------+-------+
| rec_id | name | trav_date | miles |
+--------+-------+------------+-------+
| 1 | Ben | 2014-07-30 | 152 |
| 2 | Suzi | 2014-07-29 | 391 |
| 3 | Henry | 2014-07-29 | 300 |
| 4 | Henry | 2014-07-27 | 96 |
| 5 | Ben | 2014-07-29 | 131 |
| 6 | Henry | 2014-07-26 | 115 |
| 7 | Suzi | 2014-08-02 | 502 |
| 8 | Henry | 2014-08-01 | 197 |
| 9 | Ben | 2014-08-02 | 79 |
| 10 | Henry | 2014-07-30 | 203 |
+--------+-------+------------+-------+
Search WWH ::




Custom Search