Implemented DB helper class (query) and finished implementing it in the git request for table.

This commit is contained in:
Tristan Ancelet 2023-05-27 14:41:14 -05:00
parent 52c65cea85
commit 12e1f06897
2 changed files with 18 additions and 34 deletions

View File

@ -1,4 +1,5 @@
<?php
require("../Libraries/db/query.php");
class Table_Cell {
private $formats = array(
@ -59,12 +60,18 @@ class Table_Row {
}
class Table {
private Query $query;
private $name;
private $headers;
private $rows = array();
public function __construct($name){
$this->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;

View File

@ -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 '<div class="wrapper bordered center_text">';
echo '<div class="log_table bordered">';
echo '<div class="table_row">';
if ( !empty($columns) ) {
foreach($columns as $column_name){
echo "<div class=\"table_header\">{$column_name}</div>";
}
} else {
$counter=0;
for ($i = 0; $i < $res->numColumns(); $i++ ){
echo "<div class=\"table_header\">{$res->columnName($i)}</div>";
$counter++;
}
}
echo '</div>';
while ($row = $res->fetchArray()){
echo "<div class=\"table_row\">";
if ( !empty($columns) ) {
foreach($columns as $column_name){
echo "<div class=\"table_cell\">{$row[$column_name]}</div>";
}
} else {
for ($i = 0; $i < $counter; $i++){
echo "<div class=\"table_cell\">{$row[$i]}</div>";
}
}
echo "</div>";
}
echo '</div>';
echo '</div>';
break;
case "list":