Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. // INDEX php
  2.  
  3. <div id="page-wrapper">
  4.  
  5. <div class="container-fluid">
  6.  
  7. <!-- Page Heading -->
  8. <div class="row">
  9. <div class="col-lg-12">
  10. <h1 class="page-header">
  11. Dashboard
  12. <small>Subheading</small>
  13.  
  14. </h1>
  15.  
  16.  
  17. <?php
  18.  
  19. $user = new User();
  20. $users = $user->find_all_users($user);
  21. foreach($users as $user) {
  22. echo $user->id . "<br>";
  23.  
  24. }
  25. ?>
  26.  
  27. // User php
  28.  
  29.  
  30. <?php
  31.  
  32. class User {
  33.  
  34.  
  35. public $id;
  36. public $username;
  37. public $password;
  38. public $first_name;
  39. public $last_name;
  40.  
  41.  
  42.  
  43.  
  44. public function find_all_users() {
  45. global $database;
  46. return self::find_this_query("SELECT * FROM users");
  47. }
  48.  
  49. public function find_user_by_id($user_id) {
  50. global $database;
  51. $result_set = self::find_this_query("SELECT* FROM users WHERE id = $user_id LIMIT 1");
  52. $found_user = mysqli_fetch_array($result_set);
  53. return $found_user;
  54. }
  55.  
  56.  
  57. public function find_this_query($sql) {
  58. global $database;
  59. $result_set = $database->query($sql);
  60. $the_object_array = array();
  61.  
  62. while($row = mysqli_fetch_array($result_set)) {
  63. $the_object_array[] = self::instantation($row);
  64. }
  65.  
  66.  
  67. return $the_object_array;
  68. }
  69.  
  70. public function instantation($the_record) {
  71.  
  72. $the_object = new self;
  73.  
  74. // $the_object->id = $found_user['id'];
  75. // $the_object->username = $found_user['username'];
  76. // $the_object->password = $found_user['password'];
  77. // $the_object->first_name = $found_user['first_name'];
  78. // $the_object->last_name = $found_user['last_name'];
  79.  
  80.  
  81. foreach ($the_record as $the_attribute => $value) {
  82.  
  83. if ($the_object->has_the_attribute($the_attribute)) {
  84.  
  85. $the_object->$the_attribute = $value;
  86. }
  87.  
  88. }
  89.  
  90. return $the_object;
  91. }
  92.  
  93. private function has_the_attribute($the_attribute) {
  94.  
  95. $object_properties = get_object_vars($this);
  96.  
  97. array_key_exists($the_attribute, $object_properties);
  98.  
  99. }
  100. }
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement