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 8077225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:25:47+00:00 2026-06-05T15:25:47+00:00

I currently am trying the following code: $sql = $db->query(select id,username,fullname from userss ORDER

  • 0

I currently am trying the following code:

 $sql = $db->query("select id,username,fullname from userss ORDER BY fullname ASC");
        while($row = $sql->fetch()) {
            $username[] = $row['username'];
        }
        $form = new Zend_Form();
        $form->setAction('/index/change')
             ->setMethod('post');

        $element = new Zend_Form_Element_Select('foo', array(
            'multiOptions' => array(
                $username,
                )));
        $form->addElement($element);
        echo $form;

The desired result is the <select> form showing the elements <option value='username'>Full Name</option> where username is username from SQL and Full Name is fullname from sql.

Right now, it shows <option value='0'>Full Name</option>

I’m not quite sure how to specify the first part of the array, so that it will essentially be username => Full Name

Any suggestions? Thanks!

  • 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-05T15:25:48+00:00Added an answer on June 5, 2026 at 3:25 pm

    To set the value of an option in a Zend_Form_Element_Select, the array key defines the value, and the array value defines the text in the select that the user sees.

    Try this:

    $element = new Zend_Form_Element_Select('foo', array(
        'multiOptions' => array(
            $username  => $fullname,
            $username2 => $fullname2,
    )));
    

    You were seeing 0 since the array didn’t have string keys, it defaulted to use the numerically indexed array keys as values.

    Given your code, you would do this:

    $username = array();
    
    while($row = $sql->fetch()) {
        $username[$row['username']] = $row['fullname'];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to run a passthrough query. I'm trying to run
I have the following Linq to SQL query, in which I'm trying to do
I'm trying to write a SQL query to generate a summary row for the
I have the following table: I am trying to create an SQL query that
I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I'm trying to change the current selection of a NSTableView with the following code:
I'm currently trying to do the following: Trigger: click on a name in a
I am currently trying to learn about OpenGL ES for the iPhone and following
I'm currently trying to store images in a psql table and was following this
currently I'm trying to find a regular expression with the following condition: Match: FOO_.*

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.