Frank Vèssia Posted April 15, 2016 Share Posted April 15, 2016 Hi,it's possible to get the result of a selector grouped by parents?My structure is like this restaurant 1 - dish - dish ... restaurant 2 - dish - dish ... In my search form there is a free text for searching a dish and a location. (location info is inside restaurant)The result of the search should be the list of restaurants offering that particular dish, with the dishes below.Right now I first search all restaurants in that location and after that all dishes (if they have) and display the result by restaurant.This is not the best because I have to search all restaurant I have first.I tried just to search for the dishes with parent in that location but in this way I can display only the dishes list and I need to display the restaurants list with the dishes below. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 15, 2016 Share Posted April 15, 2016 $dishes = $pages->find("…, sort=parent, sort=XX"); $parentID = null; foreach($dishes as $dish) { if($parentID === null || $dish->parent->id !== $parentID){ $parentID = $dish->parent->id; // render restaurant headline } // render dish list item } 2 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted April 15, 2016 Author Share Posted April 15, 2016 This doesn't group by parent, simply add the parent on top of each dish. I need to render all dishes of a restaurant one timeI need to search by dishes but render exactly like I have in the tree. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 15, 2016 Share Posted April 15, 2016 To add to my post above. You'd need to use "sort=parent", but if that's the case it should only render the restaurant name once and all it's dishes below it. If that's not what you want then I don't understand your request. 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted April 15, 2016 Author Share Posted April 15, 2016 yes, sort=parent was the missing point. thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now