title: How to query all entries from the database by id?
body: <p>I was following this tutorial on Udemy about building login form. Everything went well.</p>
  
  <p>Now I'm trying to reuse the code. The problem I'm having is when I'm trying to query all entries from a database in order to get a total number of websites. Could you please advise?</p>
  
  <p>Here is my count function (this is where I'm having issues in obtaining a total number of entries to the database for pagination): </p>
  
  <pre><code>function get_all_websites(){
  
          $all = array();
  
          $db = DB::getInstance();
          $all = $db-&gt;query("SELECT * FROM website");
  
          if(!$all-&gt;count()){
              echo 'No Websites available. Please check back later.';
          } else {
              foreach($all-&gt;results() as $all){
                  $all-&gt;id = $all;
              }
          }
  
          return $all;
  
      }
  
      function get_websites_count(){
  
          return count(get_all_websites());
  
      }
  </code></pre>
  
  <p>if I use this I get all ID's listed.</p>
  
  <pre><code>function get_all_websites(){
  
      $all = array();
  
      $db = DB::getInstance();
      $all = $db-&gt;query("SELECT * FROM website");
  
      if(!$all-&gt;count()){
          echo 'No Websites available. Please check back later.';
      } else {
          foreach($all-&gt;results() as $all){
              echo $all-&gt;id;
          }
      }
  
  }
  </code></pre>
  
  <p>Database class. </p>
  
  <pre><code>class DB{
          private static $_instance = null;
          private $_pdo,
                  $_query,
                  $_error = false,
                  $_results,
                  $_count = 0;
  
  
          private function __construct(){
  
              try {
                  $this-&gt;_pdo = new PDO('mysql:host=' .
                          Config::get('mysql/host') . ';dbname=' .
                          Config::get('mysql/db'),
                          Config::get('mysql/username'),
                          Config::get('mysql/password'));
  
              } catch(PDOException $e){
                  die($e -&gt; getMessage());
              }
          }
  
          public static function getInstance(){
              if(!isset(self::$_instance)) {
                  self::$_instance = new DB();
              }
              return self::$_instance;
          }
  
          public function query($sql, $params = array()){
  
              $this-&gt;_error = false;
  
              // Check if query has been prepared properly
  
              if($this-&gt;_query = $this-&gt;_pdo-&gt;prepare($sql)){
  
                  $x = 1;
                  if(count($params)){
                      foreach($params as $param){
                          $this-&gt;_query-&gt;bindValue($x, $param);
                          $x++;
                      }
                  }
  
              // If the query has been prepared successfuly, store the result
                  if($this-&gt;_query-&gt;execute()){
                      $this-&gt;_results = $this-&gt;_query-&gt;fetchAll(PDO::FETCH_OBJ);
                      $this-&gt;_count = $this-&gt;_query-&gt;rowCount();
                  } else {
                      $this-&gt;_error = true;
                  }
              }
  
              return $this;
          }
  
          public function action($action, $table, $where = array()){
              if(count($where) === 3){
                  $operators = array('=', '&gt;', '&lt;', '&gt;=', '&lt;=');
  
                  $field      = $where[0];
                  $operator   = $where[1];
                  $value      = $where[2];
  
                  if(in_array($operator, $operators)){
                      $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
  
                      if(!$this-&gt;query($sql, array($value))-&gt;error()){
                          return $this;
                      }
                  }
              }
  
              return false;
          }
  
          // QUERYING DATA FROM DATABASE
          public function get($table, $where){
              return $this-&gt;action('SELECT *', $table, $where);
          }
  
          // DELETING DATA FROM DATABASE
          public function delete($table, $where){
              return $this-&gt;action('DELETE', $table, $where);
          }
  
          // INSERTING DATA INTO DATABASE
          public function insert($table, $fields = array()){
                  $keys = array_keys($fields);
                  $values = '';
                  $x = 1;
  
                  foreach($fields as $field){
                      $values .= "?";
  
                      if($x &lt; count($fields)){
                          $values .= ', ';
                      }
                      $x++;
                  }
  
                  $sql = "INSERT INTO {$table} (`" . implode('`, `', $keys) . "`) VALUES({$values})";
  
                  if(!$this-&gt;query($sql, $fields)-&gt;error()){
                      return true;
                  }
  
              return false;
          }
  
          public function results(){
              return $this-&gt;_results;
          }
  
          public function update($table, $id, $fields){
              $set = '';
              $x = 1;
  
              foreach($fields as $name =&gt; $value){
                  $set .= "{$name} = ?";
  
                  if($x &lt; count($fields)){
                      $set .= ', ';
                  }
                  $x++;
              }
  
  
              $sql = "UPDATE {$table} SET {$set} WHERE id = {$id}";
  
              if(!$this-&gt;query($sql, $fields)-&gt;error()){
                  return true;
              }
  
              return false;
          }
  
          public function first(){
              return $this-&gt;results()[0];
          }
  
          public function error(){
              return $this-&gt;_error;
          }
  
          public function count(){
              return $this-&gt;_count;
          }
  
      }
  </code></pre>