title: Selecting table data with PDO statements
body: <p>I have a php script that selects data via mysql_, however recently I have been reading that PDO is the way to go and that mysql_ is becoming depreciated. Now I am converting that script to PDO. </p>
  
  <p>My question is though, I am not using $_POST to select. I just want to select the entire table with all of its data so I enter this query : </p>
  
  <pre><code>$query = $dbh-&gt;prepare("SELECT * FROM students");
  $query-&gt;execute();
  $result = $query-&gt;fetchall(); // or you can just $result = $query as hakre proposed!
  </code></pre>
  
  <p>so then like I did with my old depreciated mysql_ version of the script I used the echo to echo a table with the data in it. </p>
  
  <pre><code>    echo 
      "&lt;table border='2'&gt;
      &lt;tr&gt;
      &lt;th&gt;ID&lt;/th&gt;
      &lt;th&gt;A Number&lt;/th&gt;
      &lt;th&gt;First Name&lt;/th&gt;
      &lt;th&gt;Last Name&lt;/th&gt;
      &lt;th&gt;Why&lt;/th&gt;
      &lt;th&gt;Comments&lt;/th&gt;
      &lt;th&gt;Signintime&lt;/th&gt;
      &lt;/tr&gt;"
      ;
  
      foreach($result as $row)
      {
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['id'] . "&lt;/td&gt;";
    echo "&lt;td&gt;&lt;a href=Student.php?studentA_num=" . $row['anum'] . "&gt;" .$row['anum'] . " &lt;/a&gt;&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['first'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['last'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['why'] . "&lt;/td&gt;";  
    echo "&lt;td&gt;" . $row['comments'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['signintime'] . "&lt;/td&gt;";
    echo "&lt;td&gt; &lt;input type=\"button\" value=\"Start Session\"onClick=\accept.php?id=" . $row['id'] . "&amp;start=true&gt;&lt;/td&gt;";
  }
  
    echo "&lt;/tr&gt;";
    echo "&lt;/table&gt;";
  </code></pre>
  
  <p>now using this, I can not get a single output to my table. </p>
  
  <p><img src="https://i.stack.imgur.com/ZKfO9.png" alt="This is all that is being outputted"></p>
  
  <p>My question is am I missing something from my select statements? Or am I not fetching any rows? Also I the connection settings set in another script called connect.php that is required by init.php (at the top of all of my pages) </p>
  
  <p>Edit : 1</p>
  
  <p>Edited the code so it now works, also adding a picture to show others how it should look! Hopefully some one can put this to some sort of use! <img src="https://i.stack.imgur.com/C8ifY.png" alt="This is how it looks!"></p>