Jump to content

Recommended Posts

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

I did
class 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'));
}
}

view
foreach($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 table

That is like this

event_id event_name category_name status_name
   1             aaa                  xxx                       enabled
   2             bbb                 yyy                        disabled
   3             ccc                  zzz                        

where the ans should be

event_id event_name category_name status_name
   1             aaa                  zzz                       enabled
   2             bbb                 yyy                       disabled
   3             ccc                  xxx                       enabled

please help what should I do

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.