Displaying database entries for particular field in a drop down menu
<p>At the moment I am using the following code to display all the Account types in a drop down menu:</p>

<p>[HTML]</p>

<pre><code>&lt;select name="sel-account-name" id="sel-account-name" class="cp-controls-sml input-select input-select-xxlrg" tabindex="6"&gt;
    &lt;option value="0"&gt;Select Account&lt;/option&gt;

    &lt;?php echo $options?&gt;

&lt;/select&gt;
</code></pre>

<p>[PHP]</p>

<pre><code>&lt;?php

## Get all accounts from tblAccounts to display on add user page

mysql_connect('localhost', 'root', '');


mysql_select_db('database');

$sql="SELECT AccountName FROM tblaccounts";
$result=mysql_query($sql);

$options="";

while ($row=mysql_fetch_array($result)) {

    $id=$row["Id"];
    $accname=$row["AccountName"];
    $options.="&lt;OPTION VALUE=\"$accname\"&gt;".$accname.'&lt;/option&gt;';

}

?&gt;
</code></pre>

<p>Which works perfectly fine... I'm trying to write this using PDO as follows:-
I just need a little help writing this if anybody could help as I have tried but can't seem to get it to work.</p>

<pre><code>public static function getAllAccounts() {

    $pdo = new SQL();
    $dbh = $pdo-&gt;connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);

    try {

        $query = "SELECT AccountName FROM tblaccounts";


    $stmt = $dbh-&gt;prepare($query);

    $stmt-&gt;execute();

    $row = $stmt-&gt;fetch(PDO::FETCH_BOTH);

    $stmt-&gt;closeCursor();

}

catch (PDOException $pe) {
    die("Error: " .$pe-&gt;getMessage(). " Query: ".$stmt-&gt;queryString);
}

$dbh = null;

}
</code></pre>
