<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>

According to the
PHP documentation
is says you should be able to to do the following:
```
```
$sql = "SELECT * FROM widgets WHERE something='something else'";
foreach ($database->query($sql) as $row) {
   echo $row["widget_name"];
}
```
```