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

  • Home
  • SEARCH
  • 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 8174651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:30:57+00:00 2026-06-06T22:30:57+00:00

In one of my forms I would like to have a dropdown (sfWidgetFormChoice) where

  • 0

In one of my forms I would like to have a dropdown (sfWidgetFormChoice) where the options are generated dynamically by executing a query on the database.

To be a little bit more precise, I’m going to list all versions which I have in the table. The query looks something like this:

select distinct version from mytable order by version desc

What I have so far but doesn’t work:

class myForm extends sfForm

$query = "select distinct version from mytable order by version desc";

$versions = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAssoc($query);

public function configure()

$this->setWidgets(array('version' => new sfWidgetFormChoice(array('choices' => self::$versions))));

Edit:

Thansk guys for your answers! Much appreciated!

Anyhow your solutions base on having a model of the table. I’d rather have a PDO directly as it’s faster.

In the Symfony Documentation I found what I was looking for under "Using Raw SQL Queries".

So I extended my Form to end up with this:

class myForm extends sfForm
{
  public function getVersions()
  {
    $connection = Doctrine_Manager::connection();
    $query      = "select distinct version from mytable order by version desc";
    $statement  = $connection->prepare($query);
    $statement->execute();
    $resultset = $statement->fetchAll(PDO::FETCH_COLUMN, 0);

    return $resultset;
  }

  public function configure()
  {
    $this->setWidgets(array('version' => new sfWidgetFormChoice(array('choices' => self::getVersions()))));
  }
}

As a result of this my dropdown gets properly filled with what is in my table, yay! BUT I get also warnings:

Warning: Invalid argument supplied for foreach() in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/database/sfDoctrineConnectionProfiler.class.php on line 196

Warning: join() [function.join]: Invalid arguments passed in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/database/sfDoctrineConnectionProfiler.class.php on line 141

Warning: Invalid argument supplied for foreach() in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/database/sfDoctrineConnectionProfiler.class.php on line 196

Warning: Invalid argument supplied for foreach() in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/debug/sfDoctrineConnectionProfiler.class.php on line 117

Any idea what I’m doing wrong here??? Oddly enough the dropdown looks fine.

  • 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-06T22:30:59+00:00Added an answer on June 6, 2026 at 10:30 pm

    I finally found the solution I was looking for by myself. This accesses the DB now directly. The reason why I don’t use FETCH_COLUMN anymore is that this would create an array where the key is an Id starting from 0 and the value is whatever is returned by the query itself. Instead I wanted to have the key and value to be whatever the query delivers. This is why the query now delivers two columns being the same and then FETCH_KEY_PAIR does the rest.

    In case anyone else is interested in how I solved this, here is my code which is filling the drop down properly and causing no errors.

    class myForm extends sfForm
    {
      public function getVersions()
      {
        $connection = Doctrine_Manager::getInstance()->getCurrentConnection()->getDBh();
        $query      = "select distinct version as key, version as value from mytable order by version desc";
        $statement  = $connection->prepare($query);
        $statement->execute();
        $resultset = $statement->fetchAll(PDO::FETCH_KEY_PAIR);
    
        return $resultset;
      }
    
      public function configure()
      {
        $this->setWidgets(array('version' => new sfWidgetFormChoice(array('choices' => self::getVersions()))));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have one column in QTableWidget NOT editable. In forums I
What I have : A C# database query that returns two columns, one of
I have two forms on one page and want to have the input boxes
I have several forms on one page which are submitted using ajaxForm and show
I am trying to display three forms in one template. I have the forms
I have a dropdown form for one to select their graduation year -- graduation
I'm building an MVC3 application and would like to have a form with a
I have a HTML form that has a selection drop down. I would like
i have a simple dropdown menu like this below: <select name=category[] id=category class=icon-menu> <option
I have an ASP.NET web form with several UpdatePanels and I would like to

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.