PHP Error: Trying to get property of non-object

Berk

berkibap#4233
Developer
Oct 17, 2015
863
190
ellor.
so i am trying to get data from database using mysql. (im old minded ye.)
so error is
Notice: Trying to get property of non-object in C:\xampp\htdocs\odev\index.php on line 91
fetch code:
PHP:
 <div class="row text-center">
<?php require_once("ayarlar/ayar.php"); $sql = "SELECT * FROM yemekler ORDER BY id DESC";
$result = mysql_query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
      echo '            <div class="col-md-3 col-sm-6 hero-feature">
                <div class="thumbnail">
                    <img src=" '. $row["resimlink"] . '" alt="">
                    <div class="caption">
                        <h3> ' . ucwords($row["ad"]) . ' </h3>
                        <p>' . $row['yore'] .  ' yöresine ait muhteşem yemek! </p>
                        <p>
                            <a href="http://localhost/odev/yemek.php?id=' . $row["id"] . '" class="btn btn-primary">Buy Now!</a> <a href="#" class="btn btn-default">More Info</a>
                        </p>
                    </div>
                </div>
            </div>';}}?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
mysql_* isn't an object, so you can't reference things like fetch_object.

What you want is
PHP:
mysql_num_rows($result)
instead of
PHP:
$result->num_rows
and
PHP:
mysql_fetch_assoc($result)
instead of
PHP:
$result->fetch_assoc()

Have a look at MySQLi or PDO instead of using mysql_* because it is now deprecated.
 

Users who are viewing this thread

Top