formfields.com Forum Index formfields.com
FORMfields Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple Drop Downs Populated from Database

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    formfields.com Forum Index -> FF 2.X - Frequently Asked Questions (FAQs)
View previous topic :: View next topic  
Author Message
JohnConklin



Joined: 22 Dec 2006
Posts: 4
Location: Arizona, USA

PostPosted: Sat Jan 06, 2007 2:37 pm    Post subject: Multiple Drop Downs Populated from Database Reply with quote

I need to add multiple drops downs that pull data from my database.

I am trying to use:

function splitResultSet($rs) {
$values1 = array();
$values2 = array();
$i = 0;
while ( ($row = mysql_fetch_array($rs, MYSQL_NUM)) ) {
$values1[$i] = $row[0];
$values2[$i++] = $row[1];
}
return array($values1, $values2);
}

It works for the first one, but won't let me declare this more than once.

How do I create multiple drops downs that pull from different tables?

I want to pull the ID number and Description, but only display the description in my drop down.

Any and all help is greatly appreciated.

Thanks,
~John
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cisco1014



Joined: 30 Dec 2006
Posts: 2

PostPosted: Tue Feb 13, 2007 7:57 pm    Post subject: Re: Multiple Drop Downs Populated from Database Reply with quote

Why not try this:

$sql_lookup_description = getList("description select statement");
$sql_lookup_id = getList("id select statement");

$formBean->addField(new ListField("description", "Description", REQUIRED, $sql_lookup_description, $sql_lookup_id, "<Select One>", 1);

This will define a dropdown with "id"=>"description"

[note] getList is defined in dbHelpers.php
Back to top
View user's profile Send private message
JohnConklin



Joined: 22 Dec 2006
Posts: 4
Location: Arizona, USA

PostPosted: Wed Feb 14, 2007 1:57 am    Post subject: Found Solution Reply with quote

Thanks for your reply and example.

I found that I can use the same function call if I just declare each item I want to pull from the databaes seperatlly.

So, using this funciton:

Code:
      
function splitResultSet($rs) {
       $values1 = array();
       $values2 = array();
       $i = 0;
       while ( ($row = mysql_fetch_array($rs, MYSQL_NUM)) ) {
           $values1[$i] = $row[0];
           $values2[$i++] = $row[1];
          }
       return array($values1, $values2);
        }

I can then do this:

Code:
$equipID2 = DbHelper::splitResultSet(gmysql_query("SELECT DISTINCT e.EquipID, e.Description FROM equipment e JOIN orders o ON e.EquipID = o.EquipID1 ORDER BY e.EquipID"));
formBean->addField(new DropDownField("EquipID2", "Equipment Description 2", NOT_REQUIRED, $equipID2[1], $equipID2[0], "[Select Equipment 2]"));

$drivername = DbHelper::splitResultSet(gmysql_query("SELECT DriverNum, FullName FROM drivers ORDER BY FullName"));
$formBean->addField(new DropDownField("DriverName", "Driver", REQUIRED, $drivername[1], $drivername[0], "[Select Driver]"));

$trailer = DbHelper::splitResultSet(gmysql_query("SELECT ConfigNum, Description FROM trconfig WHERE OutOfService = 'No' Order By ConfigNum"));
    $formBean->addField(new DropDownField("ConfigNum", "Trailer", REQUIRED, $trailer[0], $trailer[1], "[Select Config]"));


And it works great.

~John
Code:
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    formfields.com Forum Index -> FF 2.X - Frequently Asked Questions (FAQs) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group