sort on column for table browse
authorchriskl <chriskl>
Mon, 14 Apr 2003 04:42:27 +0000 (04:42 +0000)
committerchriskl <chriskl>
Mon, 14 Apr 2003 04:42:27 +0000 (04:42 +0000)
HISTORY
classes/database/Postgres.php
tables.php

diff --git a/HISTORY b/HISTORY
index d111790704fdd22f4ebfdb712ed354d3ffdb97c8..f6a5744edda93438414aadad8648a9706aa51f8c 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -1,6 +1,11 @@
 phpPgAdmin History
 ------------------
 
+Version 3.0.0-dev-4
+-------------------
+
+* Sort on a column when browsing a table
+
 Version 3.0.0-dev-3
 -------------------
 
index 9c10ee28ebadcc5121dc02c9c775cfaf97808cd0..f3d8c0b1a491dd7d7843f48e477b6ca3a886c1bc 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.72 2003/04/08 12:51:44 chriskl Exp $
+ * $Id: Postgres.php,v 1.73 2003/04/14 04:42:27 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -647,6 +647,7 @@ class Postgres extends BaseDB {
        /**
         * Returns a recordset of all columns in a relation.  Supports paging.
         * @param $relation The name of a relation
+        * @param $sortkey Field over which to sort.  '' for no sort.
         * @param $page The page of the relation to retrieve
         * @param $page_size The number of rows per page
         * @param &$max_pages (return-by-ref) The max number of pages in the relation
@@ -655,7 +656,7 @@ class Postgres extends BaseDB {
         * @return -2 counting error
         * @return -3 page or page_size invalid
         */
-       function &browseRelation($relation, $page, $page_size, &$max_pages) {
+       function &browseRelation($relation, $sortkey, $page, $page_size, &$max_pages) {
                $oldrelation = $relation;
                $this->fieldClean($relation);
 
@@ -683,6 +684,13 @@ class Postgres extends BaseDB {
                        return -3;
                }
 
+               // Figure out ORDER BY
+               if ($sortkey != '') {
+                       $this->fieldClean($sortkey);
+                       $orderby = " ORDER BY \"{$sortkey}\"";
+               }
+               else $orderby = '';
+
                // We need to do a check to see if the relation has an OID column.  If so, then
                // we need to include it in the result set, in case the user has created a primary key
                // constraint on it.
@@ -690,9 +698,9 @@ class Postgres extends BaseDB {
 
                // Actually retrieve the rows, with offset and limit
                if ($hasID)
-                       $rs = $this->selectSet("SELECT \"{$this->id}\",* FROM \"{$relation}\" LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
+                       $rs = $this->selectSet("SELECT \"{$this->id}\",* FROM \"{$relation}\" {$orderby}LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
                else
-                       $rs = $this->selectSet("SELECT * FROM \"{$relation}\" LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
+                       $rs = $this->selectSet("SELECT * FROM \"{$relation}\" {$orderby}LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size);
                        
                $status = $this->endTransaction();
                if ($status != 0) {
index adeff949d2148667dbb02e0892b959690a75bbe1..2ecb9205599402699b4574823e2d668429d13759 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.11 2003/03/28 12:29:53 chriskl Exp $
+        * $Id: tables.php,v 1.12 2003/04/14 04:42:27 chriskl Exp $
         */
 
        // Include application functions
                $misc->printMsg($msg);
                
                if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1;
+               if (!isset($_REQUEST['sortkey'])) $_REQUEST['sortkey'] = '';
 
                // Retrieve page from table.  $max_pages is returned by reference.
-               $rs = &$localData->browseRelation($_REQUEST['table'], $_REQUEST['page'], $guiMaxRows, $max_pages);
+               $rs = &$localData->browseRelation($_REQUEST['table'], $_REQUEST['sortkey'], $_REQUEST['page'], $guiMaxRows, $max_pages);
 
                // Fetch unique row identifier, if there is one
                $key = $localData->getRowIdentifier($_REQUEST['table']);
                        reset($rs->f);
                        while(list($k, ) = each($rs->f)) {
                                if ($k == $localData->id && !$guiShowOIDs) continue;
-                               echo "<th class=data>", htmlspecialchars($k), "</th>";
+                               echo "<th class=\"data\"><a href=\"{$PHP_SELF}?action=browse&page=", $_REQUEST['page'], "&{$misc->href}&sortkey=", urlencode($k), "&table=", 
+                                       urlencode($_REQUEST['table']), "\">", htmlspecialchars($k), "</a></th>\n";
                        }
                        
                        // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET...
                                while(list($k, $v) = each($rs->f)) {
                                        if ($k == $localData->id && !$guiShowOIDs) continue;
                                        elseif ($v == '') echo "<td class=\"data{$id}\">&nbsp;</td>";
-                                       else echo "<td class=data{$id}>", nl2br(htmlspecialchars($v)), "</td>";
+                                       else echo "<td class=\"data{$id}\">", nl2br(htmlspecialchars($v)), "</td>";
                                }
                                if (sizeof($key) > 0) {
                                        $key_str = '';