RSS

CONCAT in query , Virtual Fields and make a drop down

14 May

I need to make a dropdown list of Locations. In dorpdown i need to put location name and location state name. I already have a column in database name which contain location name and location state name. Here is the steps to do so:

In Location Model(in which database table locations are saved) write the following code

1 var $virtualFields = array('dropdown_name' => 'CONCAT(Location.location_name, " ", Location.location_state)');
In Controller in which you want to show dropdown write this(eg: ShowsController):
2 $this->loadModel('Location');
$loc_list = $this->Location->find("list", array("fields" => array("location_id", 'location_name')));
$this->set('loc_list',$loc_list);
In view template(eg. View/Shows/add.php) add the following
2 $this->loadModel('Location');
$loc_list = $this->Location->find("list", array("fields" => array("location_id", 'location_name')));
$this->set('loc_list',$loc_list);
 
Leave a comment

Posted by on May 14, 2012 in Cake PHP, PHP

 

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: