title: Unable to read data from a database with PHP
body: <p>I have been working on this php to grab data from my MySQL database but it is unable to show results it just prints </p>
  
  <blockquote>
    <p>Our connection is ok! 0 results</p>
  </blockquote>
  
  <p>There are records in the database and the query works if I run it in phpMyAdmin. But it is unable to read it</p>
  
  <p><img src="https://i.imgur.com/bupVf9R.png" alt="database"></p>
  
  <pre><code>  &lt;?php
    $server = 'localhost';
    $pass = 'Blah';
    $user = 'Blah';
    $dbName = 'Blah';
  
    $db = new mysqli($server, $user, $pass, $dbName);
  
    if ($db-&gt;ping()) {
        printf ("Our connection is ok!\n");
    } else {
        printf ("Error: %s\n", $db-&gt;error);
    }
    if ($_GET['t'] == 'PL'){
        $table = 'Planets';
    } elseif ($_GET['t'] == 'SY') {
        $table = 'Systems';
    }elseif ($_GET['t'] == 'ST'){
        $table = 'Stars';
    }  else{
  
    };
  
  $sql = "SELECT * FROM Planets WHERE ID =3";
  
  $results = $db-&gt;query($sql);
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          echo $row["ID"];
        };
  } else {
      echo "0 results";
  };
  
  ?&gt;
  </code></pre>
  
  <p>Of course I have changed passwords and database details but they are correct in my version</p>