Solved

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

Posted on 2008-10-16
4
9,007 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

914 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

21 Experts available now in Live!

Get 1:1 Help Now