ajeya Posted September 9, 2014 Share Posted September 9, 2014 I have a 3-tables 1-> categories = id,category_name 2-> statuses = id,status_name 3-> evnets = id,event_name,category_id,staus_id events is the main table which has the id`s of categories and statuses table I want to display events display where the names of categories and statuses is displayed instead of name it is possible through join, but what should to model, controller and view to give the desired output. The table must display event_id, event_name,category_name,status_name Quote Link to comment https://forums.phpfreaks.com/topic/290949-how-to-display-table-with-custom-query-in-cakephp/ Share on other sites More sharing options...
ajeya Posted September 10, 2014 Author Share Posted September 10, 2014 I didclass event extends AppModel{var $belongsTo = array( 'Category' => array( 'className' => 'Category', 'foreignKey' => 'category_id', 'conditions' => 'Event.category_id=Category.id', 'fields' => '', 'order' => '' ),'Status'=>array('className' => 'Status', 'foreignKey' => 'category_id', 'conditions' => 'Event.category_id=Status.id', 'fields' => '', 'order' => '')}class EventsController extends AppController{function viewEvent(){$this->set('events',$this->Event->find('all'));}}viewforeach($events as $event_arr) {echo $event_arr['Category']['category_name'];echo $event_arr['Status']['status_name'];}It is displaying all required but without match of category-id and status-id with events tableThat is like thisevent_id event_name category_name status_name 1 aaa xxx enabled 2 bbb yyy disabled 3 ccc zzz where the ans should beevent_id event_name category_name status_name 1 aaa zzz enabled 2 bbb yyy disabled 3 ccc xxx enabledplease help what should I do Quote Link to comment https://forums.phpfreaks.com/topic/290949-how-to-display-table-with-custom-query-in-cakephp/#findComment-1490625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.