Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:54:01+00:00 2026-06-12T15:54:01+00:00

At the moment I am using the following code to display all the Account

  • 0

At the moment I am using the following code to display all the Account types in a drop down menu:

[HTML]

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

    <?php echo $options?>

</select>

[PHP]

<?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.="<OPTION VALUE=\"$accname\">".$accname.'</option>';

}

?>

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.

public static function getAllAccounts() {

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

    try {

        $query = "SELECT AccountName FROM tblaccounts";


    $stmt = $dbh->prepare($query);

    $stmt->execute();

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

    $stmt->closeCursor();

}

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

$dbh = null;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:54:03+00:00Added an answer on June 12, 2026 at 3:54 pm

    Method:

    public static function getAllAccounts() {
        $pdo = new SQL();
        $dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);
        try {
            $query = "SELECT AccountName FROM tblaccounts";
            $stmt = $dbh->prepare($query);
            $stmt->execute();
            $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
            $stmt->closeCursor();
        } catch (PDOException $pe) {
            die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
        }
        $dbh = null;
        return $rows;
    }
    

    Output:

    foreach(<classname>::getAllAccounts() as $acct) {
        $options.=sprintf('<option>%s</option>', $acct['AccountName']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I am using the following code: public void init() { question
I have the following html code. It works when using one H tag inside
At the moment I'm building a list using the following code: $('<li id=li' +
Simple question (I hope). At the moment I am using the following code: mysql_query($sql)
At the moment I am using the following bit of code to only get
At the moment I'm using the following code in my CSHTML: @{int i =
I just started using django for development. At the moment, I have the following
At the moment I'm using all sorts of if statements and substrings in order
I'm using the following code to search for addresses and list them on the
In flex, I am using the following code: mx:HBox id=box1 mouseOver=onBox('box1') mouseOut=outofBox('box1') // adding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.