function getListData($data){ $data = $this->Model->query("SELECT Model1.field1 as `Model1`,`field1` , Model1.field2 as `Model1`,`field2` , Model2.field1 as `Model2`,`field1` FROM `bars` as Model1, `barbars` as Model2, WHERE `Model2`.`barbar_id` = `Model1`.`id`"); }
$listdata = array(); foreach ($data as $item) { $listdata[$data['Model1']['field1'] = $data['Model1']['field1'] . '-' . $data['Model2']['field1']; } return $listdata; } and later, in the 'add' function: $this->set('listdata', $this->Model->getListData()); In the view: echo $html->selectTag("Player/team", $teamsportlist); Not tested but should work. Geoff -- http://lemoncake.wordpress.com On 8/10/07, Beertigger <[EMAIL PROTECTED]> wrote: > > > Still trying to concat data from two models into a select list in a > third. > > Thanks for the help thus far, Geoff. Taking your advice, and some > input from IRC, after much trying, I'm at: > > In controller: > > function getListData($data){ > $data = $this->Model->query("SELECT CONCAT(bar, ' - ', barbar) AS > foobar > FROM `bars` , `barbars` WHERE `bar`.`barbar_id` = `barbar`.`id`"); > return $data; > } > > $listdata = array(); > foreach ($data as $item) { > $listdata[$data]['Model']['foo'] = $data['Model2']['bar'] . > '-' . > $data['Model3']['barbar']; > } > > and later, in the 'add' function: > > $this->set('listdata', $this->Model->getListData()); > > In the view: > > echo $html->selectTag("Player/team", $teamsportlist, $selectedItems); > > None of this seems to be working, no matter how I jigger things about. > Aargh! > > --Beertigger > > > > On Aug 8, 6:59 pm, "Geoff Ford" <[EMAIL PROTECTED]> wrote: > > All the code I outlined would be in the controller. You could put the > loop > > in the getListData() function in the model if you like to keep the > > controller cleaner. The controller would then just be > > $this->set('listdata', $this->Model->getListData()); > > > > Geoff > > > > On 8/9/07, Beertigger <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > Somehow, this seems on the right track, but I couldn't get things to > > > work. Played around with a lot of different variations, but > > > *something* is not quite kosher, yet. > > > > > Thanks much for the guidance thus far. > > > > > Should the entire > > > > > $data = $this->Model->getListData(); // a function in your model that > > > does > > > the custom query to pull the three fields you wnat to use > > > $mylist = array(); > > > foreach ($data as $item){ > > > $mylist[$data['Model']['field1]] = $data['Model']['field2] . '-' . > > > $data['Model']['field3]; > > > > > } > > > > > be in the Model? > > > > > And the this->set in the controller? > > > > > Sorry for my blatant stupidity. Wrapping what I know of php up with > > > Cake is proving to be troublesome, at best. The masterbake script > > > provides such a sweet basic framework that a bit of pain getting > > > things 'just right' is worth it, but this one thing is really killing > > > me... ; ) > > > > > On Aug 8, 3:48 pm, "Geoff Ford" <[EMAIL PROTECTED]> wrote: > > > > OK so use HtmlHelper::select() or selectTag() - I can't remember of > the > > > top > > > > of my head which one it is. My solutions is still the same - creat > the > > > > array that you want to display in the listbox manually. > > > > > > Again not sure of the exact array format but something like > > > > > > $data = $this->Model->getListData(); // a function in your model > that > > > does > > > > the custom query to pull the three fields you wnat to use > > > > $mylist = array(); > > > > foreach ($data as $item){ > > > > $mylist[$data['Model']['field1]] = $data['Model']['field2] . '-' . > > > > $data['Model']['field3]; > > > > > > } > > > > > > $this->set("mylist", $mylist); > > > > > > Then in your view something like (again double check the format) > > > > > > $html->select("SelectName", $mylist, $selectedItems); > > > > > > I hope this helps :) > > > > > > Geoff > > > > --http://lemoncake.wordpress.com > > > > > -- http://lemoncake.wordpress.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---