@euronark How do you mean? Interesting thought. How would you get 26 records each returning 1 search_field A-Z respectfully in 1 query?
I was looking at the old code I found and posted last night and think another quick edit would be in the if: if ( $this->find('first', $params) ) { $alpha_links[$i] = 1; } else { $alpha_links[$i] = 0; } So you would end up with and real indexed array of letters rather than the 0 => 1 you should get A => 0, B => 0, C= 1. Not tested. @meat Will be around later this evening with free time and will dig up the rest of the function from the archive somewhere. K -----Original Message----- From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of euromark Sent: Friday, February 25, 2011 1:29 PM To: CakePHP Subject: Re: Search function @Krissy Masters instead of 25 single queries you could probably use a "group by" statement and a single query :) but nice idea, though On 25 Feb., 15:43, MeatSandwich <i...@babyclothingcentral.co.uk> wrote: > Hey acl68, thanks for that, definitely does point me in the right > direction. I need to go off and brush up a bit on my javascript but > hopefully what you've given me will do the job. > > thanks > > On Feb 25, 1:58 pm, acl68 <c...@anjaliebermann.de> wrote: > > > > > > > > > Hi Sandwich, > > > I did something simliar like you want to do with the checkboxes with a drop- > > down list. I didn't use the searchable-behaviour-for-cakephp but used AJAX > > instead. > > > On top of my search from ctp I includ a JavaScript file: > > <script type="text/javascript" src="/ww/js/foodselect.js"></script> > > > In my search form I have my dropdown: > > echo $this->Form->input('category_id', array('onChange' => > > 'getFoodByCategory()', 'empty' => '---')); > > > foodselect.js: > > > function getFoodByCategory() { > > var category_id = document.getElementById('UserpointCategoryId').value; > > // alert(category_id); > > > // alert('/ww/foods/getFoodByCategory/' + category_id); > > $.post('/ww/foods/getFoodByCategory/' + category_id, function(data) { > > document.getElementById('UserpointFoodIdDiv').innerHTML = data; > > }); > > > } > > > in my foods controller I have the function: > > > function getFoodByCategory($category_id = null) { > > $this->layout='ajax'; > > $this->Food->recursive = 0; > > $this->Food->order = array('Food.name asc'); > > $param = array( 'conditions' => array('Food.category_id' => > > $category_id)); $foodall = $this->Food->find('all',$param); > > foreach ($foodall as $food){ > > $li[$food['Food']['id']] = $food['Food']['name'].' ('. > > $food['Food']['points'].' Punkte)'; > > } > > > $this->set('foods',$li); > > } > > > This together fills my another dropdown with my food selection, but you can > > also have a div filles with an index table, depending what you want. > > > the output is formatted in the file /views/foods/get_food_by_category.ctp > > In my case it creates the dropdown: > > <?php > > //debug($foods); > > > echo '<select name="data[Userpoint][food_id]" id="UserpointFoodId">'; > > > foreach($foods as $key => $value){ > > echo utf8_decode ( '<option value="'.$key.'">'.$value.'</option>');} > > > echo '</select>'; > > ?> > > > In Javascript a dropdown is easier to handle than checkboxes, as you might > > know, but they should also work. > > > Hoep that example helps > > > Anja > > > Am Donnerstag, 24. Februar 2011, um 20:13:03 schrieb MeatSandwich: > > > > Hi all, > > > > I'm new to cakephp and only know a bit of php so I'm on a steep > > > learning curve since although I've made websites using php and mysql > > > before they were all a bit simple. I'm not looking for code here but > > > some pointers for me so I know what to learn. > > > > The app I'm making will end up with lots of members and I'd like to > > > make a search function so people can find other people easily. I've > > > discovered searchable-behaviour-for-cakephp and hopefully that'll > > > provide most of what I want but as another way to search rather than a > > > text box, I'd also like to have the letters of the alphabet so a user > > > can click and go straight to that letter. > > > > As well as that, members will say in their profiles what their > > > favourite animals are, ie cats/dogs/horses etc - they'll have 20 to > > > choose from. I'd like my search function to have checkboxes > > > representing each animal and someone who was searching could check the > > > dogs box and only people who like dogs will be listed, they could then > > > also check cats box and the members who like dogs and cats will be > > > shown. If possible I'd like the list to update automatically as each > > > box is clicked. > > > > I have everything else set up and only need help with this search > > > part. Assuming searchable-behaviour-for-cakephp does me for my text > > > search box, I reckon the alphabet thing will be something like making > > > a link for each letter and somehow making that link run a query, > > > hopefully that will work. > > > > But the checkbox thing that updates automatically I'm not sure about. > > > Is it ajax I need? Are there any particular methods I should be using? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. 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 -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. 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