There was a question - I am developing a news form for the site and in the same way I try to learn OOP.
$obj=new news(); $result = $obj->get_news(); while($output = mysqli_fetch_assoc($result)) { echo '<div class="product"> <div class="product_image"> <image src="/images/'.$output["id"].'.jpg" /> </div> <h2> '.$output["name"].' </h2> <div class="product_price"> '.$output["price"].' $. </div> <div class="product_buy"> <a href="/">korzina</a> </div> </div>'; } and the function of news:
require 'displaynews.php'; public $db; public function __construct(){ $this->db = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE); if(mysqli_connect_errno()) { echo "Error: Could not connect to database."; exit; } public function get_news(){ $query = 'SELECT name, price FROM news'; $result = $this -> mysqli -> query($query); return $result; } Fatal error: Call to a member function query() on a non-object in Swears at the line:
$result = $this -> mysqli -> query($query); Help to understand, please.
$this->db = ...during initialization, but you are accessing as$this->mysqliyou decide on the variable name - Mike