Solved

How can I populate a drop down (<select>) using cakePHP via MySql database

Posted on 2008-10-16
4
9,214 Views
Last Modified: 2013-12-13
I am trying to find out how to populate a HTML select object using CakePHP with a MySQL database? Say I want to fill in categories from my categories database, to keep it dynamic? Any ideas?

Thanks,

Ryan
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
wildzero earned 500 total points
ID: 22749439
Hi there,

In your controller's action you need to select all the items you want, and then send them to the view
$options = $this->Categories->find('all');
$this->set('options', $options);

Then in the view you can use the form helper like
<?php $form->input('categories' => array('options' => $options)); ?>

Thats pretty rough, but it should give you a good idea :-)
0
 
LVL 10

Expert Comment

by:wildzero
ID: 22749447
Take a look at this
http://groups.google.com/group/cake-php/browse_thread/thread/475236491480fb3d/d12c1baf5cf1f751
pretty much the same question you have, and Wayne Madison writes a pretty good reply
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22778966
Thank you! I want to keep playing with Cake to build some apps! I feel like when you understand it you can start to develp apps on the fly or well i should say much faster than traditional PHP.

Ryan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question