Implemented table classes for each webpage.

This commit is contained in:
2023-05-27 15:53:50 -05:00
parent 12e1f06897
commit b8ba9dc5d4
9 changed files with 95 additions and 85 deletions

View File

@@ -1,8 +1,11 @@
<?php
namespace db;
class Query {
private $table_name;
private array $columns_querying = array();
private int $limit=0;
private string $order_by;
public function __construct(string $table_name){
$this->table_name = $table_name;
@@ -19,6 +22,10 @@ class Query {
}
}
public function set_order_by_column (string $order_by){
$this->order_by = $order_by;
}
private function get_columns(){
$column_string="";
@@ -39,13 +46,21 @@ class Query {
return $modifier;
}
private function get_order_by(){
$order_by="";
if (!empty($this->order_by)){
$order_by=" ORDER BY {$this->order_by}";
}
return $order_by;
}
private function get_where() {
$where = "";
return $where;
}
public function get_query_string(){
$query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_limit()};";
$query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_order_by()}{$this->get_limit()};";
return $query;
}

View File

@@ -1,5 +1,9 @@
<?php
require("../Libraries/db/query.php");
namespace table;
$root = $_SERVER['DOCUMENT_ROOT'];
include("$root/Libraries/db/query.php");
use db\Query;
class Table_Cell {
private $formats = array(
@@ -62,6 +66,7 @@ class Table_Row {
class Table {
private Query $query;
private $name;
private $pretty_name;
private $headers;
private $rows = array();
@@ -83,6 +88,18 @@ class Table {
public function set_name($name){
$this->name = $name;
}
public function set_pretty_name(string $pretty_name){
$this->pretty_name = $pretty_name;
}
public function get_pretty_name(){
$output=$this->name;
if (!empty($this->pretty_name)){
$output=$this->pretty_name;
}
return $output;
}
public function Load($db){
$res = $db->query($this->query->get_query_string());
@@ -108,7 +125,7 @@ class Table {
}
public function get_html(){
$output="";
$output="{$output}<div class=\"wrapper bordered center_text\">";
$output="{$output}<div class=\"wrapper bordered center_text\">{$this->get_pretty_name()}";
$output="{$output}<div class=\"log_table bordered\">";
foreach ($this->rows as $row){

View File

@@ -1,6 +1,7 @@
<?php
require("class.php");
use table\Table;
function get_main () {
$db = $GLOBALS["db"];
/*