Solved

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

Posted on 2008-10-16
4
8,963 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now