From 12e1f0689736d215717786d93c5c032509c6976c Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sat, 27 May 2023 14:41:14 -0500 Subject: [PATCH] Implemented DB helper class (query) and finished implementing it in the git request for table. --- Libraries/table/class.php | 11 +++++++++-- Libraries/table/get.php | 41 +++++++++------------------------------ 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/Libraries/table/class.php b/Libraries/table/class.php index 60eed09..77b5aa3 100644 --- a/Libraries/table/class.php +++ b/Libraries/table/class.php @@ -1,4 +1,5 @@ set_name($name); + $this->query = new Query($name); + } + + public function get_query(){ + return $this->query; } private function add_row(){ @@ -77,8 +84,8 @@ class Table { $this->name = $name; } - public function Load($db, $query_modifier){ - $res = $db->query("SELECT * FROM $this->name $query_modifier"); + public function Load($db){ + $res = $db->query($this->query->get_query_string()); // Getting header row $col_count=0; diff --git a/Libraries/table/get.php b/Libraries/table/get.php index f4fab09..2ea5198 100644 --- a/Libraries/table/get.php +++ b/Libraries/table/get.php @@ -28,6 +28,8 @@ function get_main () { return 1; } else { $name=$_GET['name']; + $table = new Table($name); + $query = $table->get_query(); } if ( array_key_exists("limit", $_GET)){ @@ -36,9 +38,13 @@ function get_main () { $limit=0; } + $query->set_limit($limit); + if ( array_key_exists("columns", $_GET)){ $columns = explode(',', $_GET["columns"]); } + + $query->set_columns($columns); // END: Get show args $query_modifier=""; @@ -49,39 +55,10 @@ function get_main () { }else { $query_modifier=""; } + $table->Load($db); + $output = $table->get_html(); + echo $output; - $res = $db->query("SELECT * FROM $name $query_modifier"); - echo '
'; - echo '
'; - echo '
'; - if ( !empty($columns) ) { - foreach($columns as $column_name){ - echo "
{$column_name}
"; - } - } else { - $counter=0; - for ($i = 0; $i < $res->numColumns(); $i++ ){ - echo "
{$res->columnName($i)}
"; - $counter++; - } - } - - echo '
'; - while ($row = $res->fetchArray()){ - echo "
"; - if ( !empty($columns) ) { - foreach($columns as $column_name){ - echo "
{$row[$column_name]}
"; - } - } else { - for ($i = 0; $i < $counter; $i++){ - echo "
{$row[$i]}
"; - } - } - echo "
"; - } - echo '
'; - echo '
'; break; case "list":