I am comfortable with PHP and MySQL, but I'm new to Drupal, though I've just finished all chapters from Pro Drupal Development (VandDyk and Westgate). I need to create a form which populates a drop-down list from a column in a table, like Apples, Bananas, Pears. Should I create a .module, or am I overlooking a CCK extension module and/or Views approach? Thanks!
Sean, You can use a CCK select field and define the allowed values using PHP. Your code would look something like this: $values = array(); $results = db_query("select id, name from {table}"); while ($result = db_fetch_array($results)) { $values[$result['id']] = $result['name'] } return $values; Thanks, Brad -- Aten Design Group Phone: 303.831.0449
Thanks for the reply, Brad! Just to be sure though, since I don't want to re-invent the wheel if there's a module already, but there isn't a module to do table column lookups, 'programmable' via widgets, instead of code? I need to pass this project onto a non-technician for ongoing support and maintenance, and that person won't understand any PHP code. Sean -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Brad Bowman Sent: Friday, March 14, 2008 9:36 AM To: development@drupal.org Subject: Re: [development] CCK lookup and drop-down list Sean, You can use a CCK select field and define the allowed values using PHP. Your code would look something like this: $values = array(); $results = db_query("select id, name from {table}"); while ($result = db_fetch_array($results)) { $values[$result['id']] = $result['name'] } return $values; Thanks, Brad -- Aten Design Group Phone: 303.831.0449
On Fri, Mar 14, 2008 at 2:21 PM, Sean Wingert <seanw@norris-stevens.com> wrote:
I am comfortable with PHP and MySQL, but I'm new to Drupal, though I've just finished all chapters from Pro Drupal Development (VandDyk and Westgate).
Ahh, but have they finished with you?
I need to create a form which populates a drop-down list from a column in a table, like Apples, Bananas, Pears. Should I create a .module, or am I overlooking a CCK extension module and/or Views approach?
I was perusing the module list just yesterday, and it seems there is such a module. See if Fixed Data Dropdown<http://drupal.org/project/FixedDataDropdown>is of any use to you ( http://drupal.org/project/FixedDataDropdown ) . "Allows a user to select data stored into a large database with dependent selection choice (e.g. Country -> City)" Thanks!
participants (3)
-
Brad Bowman -
Sean Wingert -
Victor Kane