Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // INDEX php
- <div id="page-wrapper">
- <div class="container-fluid">
- <!-- Page Heading -->
- <div class="row">
- <div class="col-lg-12">
- <h1 class="page-header">
- Dashboard
- <small>Subheading</small>
- </h1>
- <?php
- $user = new User();
- $users = $user->find_all_users($user);
- foreach($users as $user) {
- echo $user->id . "<br>";
- }
- ?>
- // User php
- <?php
- class User {
- public $id;
- public $username;
- public $password;
- public $first_name;
- public $last_name;
- public function find_all_users() {
- global $database;
- return self::find_this_query("SELECT * FROM users");
- }
- public function find_user_by_id($user_id) {
- global $database;
- $result_set = self::find_this_query("SELECT* FROM users WHERE id = $user_id LIMIT 1");
- $found_user = mysqli_fetch_array($result_set);
- return $found_user;
- }
- public function find_this_query($sql) {
- global $database;
- $result_set = $database->query($sql);
- $the_object_array = array();
- while($row = mysqli_fetch_array($result_set)) {
- $the_object_array[] = self::instantation($row);
- }
- return $the_object_array;
- }
- public function instantation($the_record) {
- $the_object = new self;
- // $the_object->id = $found_user['id'];
- // $the_object->username = $found_user['username'];
- // $the_object->password = $found_user['password'];
- // $the_object->first_name = $found_user['first_name'];
- // $the_object->last_name = $found_user['last_name'];
- foreach ($the_record as $the_attribute => $value) {
- if ($the_object->has_the_attribute($the_attribute)) {
- $the_object->$the_attribute = $value;
- }
- }
- return $the_object;
- }
- private function has_the_attribute($the_attribute) {
- $object_properties = get_object_vars($this);
- array_key_exists($the_attribute, $object_properties);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement