datatable, get post with param class. where query working.

This commit is contained in:
2023-10-17 13:28:49 +07:00
parent 9bea66a705
commit 7d359fbd68
+22 -10
View File
@@ -6,7 +6,7 @@
Desc. : v4 - HTML Table (jQuery & Bootstrap) Desc. : v4 - HTML Table (jQuery & Bootstrap)
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : January 16th, 2008. Created Date : January 16th, 2008.
Last Modified : October 16th, 2023. Last Modified : October 17th, 2023.
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM. (c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
@@ -17,7 +17,9 @@ declare(strict_types=1);
namespace siaupheng\fonia3\Web; namespace siaupheng\fonia3\Web;
final class Table { final class Table {
private $__table = ""; private $__ttable = "";
private $__tfield = "";
private $__twhere = "";
private $__tquery = ""; private $__tquery = "";
private $__tquery_footer = ""; private $__tquery_footer = "";
private $__aheader = []; private $__aheader = [];
@@ -44,14 +46,18 @@ final class Table {
private $__tcss = ""; private $__tcss = "";
private $__livedata = false; private $__livedata = false;
protected $__cdb = null; protected $__cdb = null;
protected $__cpa = null;
public function __construct($db = null){ public function __construct($db = null){
if (is_resource($db)) { $this->__cdb = $db; } if (is_resource($db)) { $this->__cdb = $db; }
else { $this->__cdb = new \siaupheng\fonia3\DB\MySQL(); } else { $this->__cdb = new \siaupheng\fonia3\DB\MySQL(); }
$this->__cpa = new \siaupheng\fonia3\Web\Param();
} }
public function set_table($ttable = "") { public function set_table($ttable = "", $tfield = "", $twhere = "") {
$this->__table = $ttable; $this->__ttable = $ttable;
if ($tfield != "") $this->__tfield = $tfield;
if ($twhere != "") $this->__twhere = $twhere;
} }
public function set_query($tquery = "") { public function set_query($tquery = "") {
@@ -227,10 +233,11 @@ final class Table {
public function db_table($nama_tabel = "tabel_", $baris_tabel = 10) { public function db_table($nama_tabel = "tabel_", $baris_tabel = 10) {
$this->__livedata = true; $this->__livedata = true;
$id_draw = intval($_REQUEST['draw'] ?? 0);// $this->prepare_query();
$i_start = intval($_REQUEST['start'] ?? 0);// $id_draw = intval($this->__cpa->Get("draw", 0));
$i_length = intval($_REQUEST['length'] ?? 0);// $i_start = intval($this->__cpa->Get("start", 0));
$i_order = intval($_REQUEST['order'] ?? 0);// $i_length = intval($this->__cpa->Get("length", 0));
$i_order = intval($this->__cpa->Get("order", 0));
if ($id_draw > 0) { if ($id_draw > 0) {
$t_order = "ASC"; $t_order = "ASC";
@@ -242,14 +249,14 @@ final class Table {
$sql_order = ($this->__afield[$i_order]) ? " ORDER BY ".$this->__afield[$i_order]." ".$t_order : ""; $sql_order = ($this->__afield[$i_order]) ? " ORDER BY ".$this->__afield[$i_order]." ".$t_order : "";
$record = 0; $record = 0;
$this->__cdb->Query("SELECT COUNT(*) Item FROM ".$this->__table); $this->__cdb->Query("SELECT COUNT(*) Item FROM ".$this->__ttable.$this->__twhere);
if ($this->__cdb->Next()) $record = intval($this->__cdb->Row("Item", 0)); if ($this->__cdb->Next()) $record = intval($this->__cdb->Row("Item", 0));
$adata['draw'] = $id_draw; $adata['draw'] = $id_draw;
$adata['recordsTotal'] = $record; $adata['recordsTotal'] = $record;
$adata['recordsFiltered'] = $record; $adata['recordsFiltered'] = $record;
$adata['data'] = []; $adata['data'] = [];
$this->__cdb->Query("SELECT `".implode('`,`', $this->__afield)."` FROM ".$this->__table.$sql_order.$sql_limit); $this->__cdb->Query("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere.$sql_order.$sql_limit);
while ($this->__cdb->Next()) { while ($this->__cdb->Next()) {
$abaris = []; $abaris = [];
$aoption = ['button'=>[]]; $aoption = ['button'=>[]];
@@ -293,6 +300,11 @@ final class Table {
} }
return $adata; return $adata;
} }
private function prepare_query() {
if ($this->__tfield == "") $this->__tfield = "`".implode('`,`', $this->__afield)."`";
if ($this->__twhere != "") $this->__twhere = " WHERE " . $this->__twhere;
}
} }
?> ?>