I'm working with someone else's CakePHP code, with minimal knowledge of PHP, so this may be a very basic question.
Within a controller, the following code begins to create an array that's then passed to a .ctp file:
$prefs_by_user = $this->PanelPref->find('all', array(
'fields' => array(
'UserTimeSlot.day_time_slot_id', 'PanelPref.panel_id', 'Panel.name',
'COUNT(DISTINCT PanelPref.user_id) AS panels_int' ,
Within PanelPref are panel ratings that may equal 1, 2, or 3. I would like to add fields that count how many people have given this particular panel each rating. I attempted this:
'COUNT(PanelPref.panel_rating_id = 3) AS rated_three',
'COUNT(PanelPref.panel_rating_id = 2) AS rated_two',
'COUNT(PanelPref.panel_rating_id = 1) AS rated_one',
but all that does is count PanelPref.panel_rating_id and since there are as many ratings as there are users, all the variables end up with the same value.
I've tried using == and => instead of =, but they return errors.
I've tried COUNT(PanelPref.panel_rating_id WHERE PanelPref.panel_rating_id = 3) AS rated_three and gotten an error.
I've tried using array_count_values but it doesn't seem to work within the array fields (and I'm probably not using it properly anyway).
Any thoughts on how to make this work? It's not vital but I would really like to have it.