if (isset($this->data['Genre']['id']) && is_array($this->data['Genre']['id']) && !in_array('51', $this->data['Genre']['id'])) { $this->data['Genre'][] = 51; // or, array_push($this->data['Genre'], 51); }
On Thu, Jan 22, 2009 at 8:28 PM, kai <k3ho...@gmail.com> wrote: > > In $this->data: > [Genre] => Array > ( > [id] => Array > ( > [0] => 2 > [1] => 55 > ) > > ) > In sql: > WHERE `Genre_id` IN ('2', '55') > > Yeah, I want to add to their selection, not override it. > > On Jan 22, 5:21 pm, brian <bally.z...@gmail.com> wrote: >> If a user "chooses a genre" what does the data look like? Before your >> code does anything. Is it well formed? >> >> If you want to set ['Genre']['id'] to some value, what does the data >> look like before that? It seems like you're trying to override the >> user's selection, rather than add to it. Do you want to add ID=51 *in >> addition* to whatever genre ID the user passes? >> >> On Thu, Jan 22, 2009 at 8:09 PM, kai <k3ho...@gmail.com> wrote: >> >> > When a user submits a form I'm hoping to apply some logic to their >> > choice. The form takes user input and translates their selection into >> > conditions to use in a query. One part of the selection is the choice >> > to choose a genre. I'm hoping to say something like, if user chooses >> > one genre or more then also add 'this genre' to their query. I tried >> > something like: >> >> > if (!empty($this->data['Genre']['id']) and count($this->data['Genre'] >> > ['id']) > 0) { >> > $this->data['Genre']['id'] = 51; >> > } >> >> > but have found that $this->data['Genre']['id'] = 51; does nothing. How >> > can i force genre 51 to become part of the query if the user chooses >> > at least one genre? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---