From ddd7d0d9ca81653a01767b95551425886e0c6127 Mon Sep 17 00:00:00 2001 From: Aamir Shahzad Date: Sat, 18 Nov 2023 06:07:31 +0500 Subject: [PATCH] Updated add record, still not completed --- Example1/Add.php | 3 ++ Example1/Example1.php | 14 +++++- Example1/View.php | 9 ++++ Example1/index.php | 3 ++ Example2/Example2.php | 42 +++++++++++++++++ Example2/index.php | 9 ++++ PRC.php | 106 ++++++++++++++++++++++++++++++++++++------ example.sql | 25 +++++++++- 8 files changed, 194 insertions(+), 17 deletions(-) create mode 100644 Example1/View.php create mode 100644 Example2/Example2.php create mode 100644 Example2/index.php diff --git a/Example1/Add.php b/Example1/Add.php index f88dd80..55fca09 100644 --- a/Example1/Add.php +++ b/Example1/Add.php @@ -1,4 +1,7 @@ tblName = 'example1'; + parent::__construct(); - $this->tblName = 'example1'; - $this->auth = "WHERE user_id = {$_SESSION['user_id']}"; + $this->auth = "WHERE user_id = {$_SESSION['user_id']}"; // we may adjust or fix it later on $this->tblCols = array( 'id' => array( + 'type' => 'text', 'display as' => 'ID', 'is display' => array( 'on listing' => true, + 'on view' => false, 'on add' => false, 'on edit' => false, ), + 'is required' => true, ), 'name' => array( + 'type' => 'text', 'display as' => 'Name', 'is display' => array( 'on listing' => true, + 'on view' => true, 'on add' => true, 'on edit' => true, ), + 'is required' => true, ), 'date' => array( + 'type' => 'date', 'display as' => 'Date', 'is display' => array( 'on listing' => true, + 'on view' => true, 'on add' => true, 'on edit' => true, ), + 'is required' => false, ), ); } // __construct() diff --git a/Example1/View.php b/Example1/View.php new file mode 100644 index 0000000..f2a4650 --- /dev/null +++ b/Example1/View.php @@ -0,0 +1,9 @@ +view(); \ No newline at end of file diff --git a/Example1/index.php b/Example1/index.php index 23e1d2c..6e542bb 100644 --- a/Example1/index.php +++ b/Example1/index.php @@ -1,4 +1,7 @@ tblName = 'example2'; + + parent::__construct(); + + $this->tblCols = array( + 'id' => array( + 'type' => 'text', + 'display as' => 'ID', + 'is display' => array( + 'on listing' => true, + 'on view' => false, + 'on add' => false, + 'on edit' => false, + ), + 'is required' => true, + ), + 'name' => array( + 'type' => 'text', + 'display as' => 'Name', + 'is display' => array( + 'on listing' => true, + 'on view' => true, + 'on add' => true, + 'on edit' => true, + ), + 'is required' => true, + ), + ); + } // __construct() + + function __destruct() { + parent::__destruct(); + } // __destruct() +} // class \ No newline at end of file diff --git a/Example2/index.php b/Example2/index.php new file mode 100644 index 0000000..209ae96 --- /dev/null +++ b/Example2/index.php @@ -0,0 +1,9 @@ +list(); \ No newline at end of file diff --git a/PRC.php b/PRC.php index dd5611c..582039c 100644 --- a/PRC.php +++ b/PRC.php @@ -13,6 +13,9 @@ class PRC protected $appPathUrl = 'http://localhost/PRC'; protected $dbConn; protected $tblName; + protected $tbl; + protected $tblNameUcF; + protected $isTblNamePlural = true; protected $tblCols; protected $showHTML = true; protected $auth = false; @@ -41,6 +44,8 @@ function __construct($opt = null) 'example' // Database name, notice no "," ); + $this->tblNameUcF = ucfirst($this->tblName ?? false); + if ($this->showHTML) { ?> @@ -64,10 +69,18 @@ function __construct($opt = null) $all = array_diff(scandir($dir), [".", "..", ".git"]); foreach ($all as $ff) { - if (is_dir($dir . $ff)) { - echo "appPathUrl}/{$ff}\">{$ff} |"; - } - } + if (is_dir($dir . $ff)) { + // pr($ff,'$ff'); + // pr($this->tblName,'$this->tblName'); + + if ($ff == $this->tblNameUcF) { + echo "{$ff} | "; + } + else { + echo "appPathUrl}/{$ff}\">{$ff} | "; + } // if + } // if is_dir + } // foreach all ?> Logout @@ -89,6 +102,7 @@ function list() $headers .= "{$tblCol['display as']}"; $fields .= "{$this->tblName}.{$key}, "; $displayColCount++; + // Maybe limit headers/values to 10 or some columns } // foreach (tblCols) $fields = rtrim($fields,', '); @@ -107,10 +121,10 @@ function list() // print_r($cols); } // if ($result->num_rows) - $tblNameUcF = ucfirst($this->tblName); + // $tblNameUcF = ucfirst($this->tblName); ?>
-

+ (add new record)

+

tblNameUcF ?> + (add new record)

{$row[$key]}"; } // foreach (tblCols) - echo ''; + echo ""; ?> tblCols as $key => $tblCol) { + if ($tblCol['is display']['on view'] === false) { + continue; + } + + $fields .= "{$this->tblName}.{$key}, "; + // Maybe limit headers/values to 10 or some columns + } // foreach (tblCols) + + $fields = rtrim($fields,', '); + + $sql = "SELECT $fields FROM {$this->tblName} {$this->auth};"; + // print_r($sql); + + $result = mysqli_query( + $this->dbConn, + $sql + ); + + if (mysqli_num_rows($result)) { + $row = mysqli_fetch_assoc($result); + $cols = array_keys($row); + // print_r($cols); + } // if ($result->num_rows) + + // $tblNameUcF = ucfirst($this->tblName); + ?> +
+

tblNameUcF ?>

+ +
+

$_POST

'; - print_r($_POST); - echo ''; + $this->pr($_POST,'$_POST'); + $tblName = ucfirst($this->isTblNamePlural ? rtrim($this->tblName,'s') : $this->tblName); ?>
-

Add tblName,'s')) ?>

+

Add

tblCols as $key => $tblCol) { if ($tblCol['is display']['on add'] === false) { continue; } + + // $this->pr($key,'$key'); + // $this->pr($tblCol,'$tblCol'); + + // switch ($key) { + // case 'date': + // break; + + // default: + // break; + // } // switch key ?>
- + + >

- +
dbConn); // optional } // __destruct() -} // class PRC \ No newline at end of file +} // class PRC + +function pr($value,$name) +{ + $count = is_countable($value) ? count($value) : null; + + echo "

Name: {$name}, Count:{$count}

"; + print_r($value); + echo '
'; +} // pr() \ No newline at end of file diff --git a/example.sql b/example.sql index 3427fb6..7914cfb 100644 --- a/example.sql +++ b/example.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: localhost --- Generation Time: Nov 17, 2023 at 05:16 AM +-- Generation Time: Nov 18, 2023 at 02:04 AM -- Server version: 10.4.28-MariaDB -- PHP Version: 8.2.4 @@ -38,6 +38,17 @@ CREATE TABLE `example1` ( -- -------------------------------------------------------- +-- +-- Table structure for table `example2` +-- + +CREATE TABLE `example2` ( + `id` int(10) UNSIGNED NOT NULL, + `name` varchar(255) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +-- -------------------------------------------------------- + -- -- Table structure for table `users` -- @@ -60,6 +71,12 @@ ALTER TABLE `example1` ADD PRIMARY KEY (`id`), ADD KEY `user_id` (`user_id`); +-- +-- Indexes for table `example2` +-- +ALTER TABLE `example2` + ADD PRIMARY KEY (`id`); + -- -- Indexes for table `users` -- @@ -77,6 +94,12 @@ ALTER TABLE `users` ALTER TABLE `example1` MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT; +-- +-- AUTO_INCREMENT for table `example2` +-- +ALTER TABLE `example2` + MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT; + -- -- AUTO_INCREMENT for table `users` --
Edit | DeleteappPathUrl}/{$this->tblNameUcF}/View.php\">View | Edit | Delete