title: How do I loop through a MySQL query via PDO in PHP?
body: <p>I'm slowly moving all of my <code>LAMP websites</code> from <code>mysql_</code> functions to <code>PDO</code> functions and I've hit my first brick wall.  I don't know how to loop through results with a parameter.  I am fine with the following:</p>
  
  <pre><code>foreach ($database-&gt;query("SELECT * FROM widgets") as $results)
  {
     echo $results["widget_name"];
  }
  </code></pre>
  
  <p>However if I want to do something like this:</p>
  
  <pre><code>foreach ($database-&gt;query("SELECT * FROM widgets WHERE something='something else'") as $results)
  {
     echo $results["widget_name"];
  }
  </code></pre>
  
  <p>Obviously the 'something else' will be dynamic.</p>