-1

So this is my code, but whenever I run this code i get this message (Notice: Trying to get property 'num_rows' of non-object in F:\xampp\htdocs\php\index.php on line 31) and I can't find the problem. I always use num_rows and it works, this is the first time this happened

 <?php
$mysqli = new mysqli ('localhost','root','','instruments');
if(isset($_GET['order']))
{
$order = $_GET ['order'];
}else{
  $order = 'price';
}
if(isset($_GET['sort']))
{
$sort = $_GET ['sort'];
}else{
  $sort = 'ASC';
}

$result = $mysqli->query("SELECT * FROM bass ORDER BY $order $sort");
if($result->num_rows > 0)
{
echo "
<table border = '1'>
<tr>
<th>Price</th>
<th>Rate</th>
";
while($rows = $result->fetch_assoc())
{

      $name = $rows ['name'];
  $price = $rows ['price'];
  $rate = $rows ['rate'];
  $image = $rows ['image'];

  echo "
  <tr>
  <td>$name</td>
 <td>$price</td>
 <td>$rate</td>
 <td><img src='$image'></td>
   </tr>
  ";
}
echo "
</table>
";
}else {
  echo "Nic ni";
}
 ?>

1 Answers1

0

Run this query in your MySQL:

SELECT * FROM bass ORDER BY price ASC

Check if you get any result. Maybe your query is returning 0 results and that's why it's failing.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40