title: Using PHP to query a database and return results to display on a webpage
body: <p>I'm trying to select some simple information from a database and display it on a webpage. I can't work out for the life of me why if ($result->num_rows > 0) from the code below evaluates to false. Most of this is copied directly from the W3Schools site from: <a href="http://www.w3schools.com/php/php_mysql_select.asp" rel="nofollow">http://www.w3schools.com/php/php_mysql_select.asp</a> 
  So it really shouldn't have anything wrong with it..</p>
  
  <pre><code>&lt;html&gt;
   &lt;div class="panel"&gt; 
   &lt;!--this should print out atleast something from the database, but it's printing 0 results. --&gt;
  &lt;?php include("populate_feature_list.php"); ?&gt;
   &lt;/div&gt;
   &lt;/html&gt;           
  </code></pre>
  
  <p>This is the contents of the included PHP file:
      
  
  <pre><code>// Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  
  $sql = mysql_query($conn,"SELECT name, rating FROM table ORDER BY rating DESC LIMIT 5;");
  
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          echo "Provider: " . $row["name"]. " - Rating: " . $row["rating"]. "&lt;br&gt;";
      }
  } else {
      echo "0 results";
  }
  $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>This is what returns on the SQL server when executing the query: </p>
  
  <pre><code>    +----------------------+--------+
      | name                 | rating |
      +----------------------+--------+
      | persona              | 4.8000 |
      | personb              | 4.7500 |
      | personc              | 4.6500 |
      | persond              | 4.1500 |
      | persone              | 2.4000 |
      +----------------------+--------+
  </code></pre>
  
  <p>And  description of table:</p>
  
  <pre><code>+--------+-------------+------+-----+---------+-------+
  | Field  | Type        | Null | Key | Default | Extra |
  +--------+-------------+------+-----+---------+-------+
  | name   | varchar(20) | YES  | UNI | NULL    |       |
  | rating | float(8,4)  | YES  |     | NULL    |       |
  +--------+-------------+------+-----+---------+-------+
  </code></pre>