SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot mrtopher's Avatar
    Join Date
    Mar 2004
    Location
    VA
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HTML_QuickForm selects

    Can anyone tell me how I can create a select (drop down) box on a PEAR::HTML_QuickForm form that is populated with values I get from a database?

  2. #2
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might find something usefull here: http://www.thelinuxconsultancy.co.uk/quickform.html

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  3. #3
    SitePoint Zealot mrtopher's Avatar
    Join Date
    Mar 2004
    Location
    VA
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zoef,

    I looked at that site. As far as I can tell, it only shows how to create hierselect. I dont see any information on how to create a select from a database query results.

    I looked at the PEAR resources and it said something about using the addOption() function, but when I try that I get an error saying that it doesnt exist. I think all I have to do is take the array of values I get from my query and put it in the right format for the QuickForm element to read but I'm not sure how to do that.

  4. #4
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code listing 5.1 on that page has an example using 'select'.

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  5. #5
    SitePoint Zealot mrtopher's Avatar
    Join Date
    Mar 2004
    Location
    VA
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That helps

    I am able to get values to show up in my drop down, but the format of my array is incorrect so it doesnt show up in the drop down correctly.

    $sql = "select clientID, company from clientInfo";
    $result = $db->query($sql);
    $clients = $result->fetch();

    When I run the query above I get results like:
    Array ( [clientID] => 1, [company] => JEC Construction )

    This is a problem because the drop down ends up showing "1" and "JEC Construction" as selectable options with values of "clientID" and "company". I am looking to get an array formatted like:

    Array ( 1 => JEC Construction, 2 => Something Else )

    clientID => company

    Is there a way for me to reformat my array so it can be inserted into QuickForm correctly?

  6. #6
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing that you have to realize is that the fetch() method returns one row at the time. This row is in the shape of array(col1name => col1value, col2name => col2value, col3Na... ). Then the fetch() method also moves the 'pointer' 1 notch up, so that the next time you call fetch() it will retrieve the next row.

    Standard way of dealing with this is with a while loop. In that loop you can then 'format' the data from that row in any way you want. This should work for you:
    PHP Code:
    $sql "select clientID, company from clientInfo";
    $result $db->query($sql);

    $client = array();
    while (
    $row $result->fetch() ) {
        
    $client[$row['clientID']] = $row['company'];

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •