-1

The connection to database is working. The display_all() is the problem. It is not displaying results as it show can someone please help pinpoint where the problems may lie.? I am quite new to php and I have just spent some hours on this but dont know were the problem is. I am trying to display results from database. I would like if someone can just pinpoint the exact place where the problem or fact is in the programme.

<?php

class connect_dbase{

public $mysqli;

  public function connection($host="localhost",$user="root",$password="london",$db_name="users")
  {
    $this->mysqli=new mysqli($host,$user,$password,$db_name);
    if ($this->mysqli->connect_error) {
      die('Connect Error: ' . $this->mysqli->connect_error);
    }
    else 
    {
      echo " Database connection successful";
    }
  }

  public function display_all($id)    
  {
    if($stmt = $this->mysqli->prepare("SELECT * FROM user WHERE id =?"))
    {
      /* bind parameters for markers */
      $stmt->bind_param('i',$id);

      /* execute query */
      $stmt->execute();

      if($stmt->num_row() >0)
      { 
        echo 'Total results: ' . $resultrol->num_rows;
        $result = $stmt->get_result();
        while ($row = $result->fetch_assoc()) {
          // do something with $row  
          echo $row['name'];
        }  
      }
      else
      {  
        echo "no result found";
      }
    }
    else
    {  
      echo "cant prepare result";
    }     
  }
}
$connect_dbase=new connect_dbase();

$connect_dbase->connection();
$connect_dbase->display_all(2);
?>
eebbesen
  • 5,070
  • 8
  • 48
  • 70

1 Answers1

1
echo 'Total results: ' . $resultrol->num_rows;
    $result = $stmt->get_result();

Shouldn't $resultrol be undefinded?

Eisa Adil
  • 1,743
  • 11
  • 16