Jump to content

CrazyEnimal

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by CrazyEnimal

  1. Yes! explode() sounds like cool method! But after explode() i try to do unique() of filter() and get 500 error ? in erro message I see "Fatal Error: Uncaught Error: Call to a member function unique() on array in" I need to get a unique manufacturer array as well as the number of manufacturer repeats in the array. Do you now how I can do this ? Thanks a lot!
  2. Hello! I had a problem which is as follows: using the $pages->find($selectors) method; I can get an array of pages in the system. Is there any way to get an array of fields instead of an array of pages? for example as in SQL query using not SELECT * FROM table WHERE fieldname=value; And I need to get an array of one field as here: SELECT some_field FROM table WHERE another_field=value;? Let me explain: There is an array of pages with the template "Car" where there are fields of type Manufacturer, Model, etc. which are of type Page Reference. Suppose I found all Cars with certain parameters $selectors = "parent=$parent,template=page_car,dealer={$dealer_id}"; $cars = $pages->findMany($selectors); And if I need to find all the manufacturers that can be in $cars I do it in the following way: $manufacturerParent = wire("pages")->get($manufacturerParentID); $manufacturerList = wire("pages")->findMany("parent={$manufacturerParent}"); foreach($manufacturerList as $manufacturerItem) { // I'm get all cars with selectors and with this manufacturer. $carsInManifacturerCount = wire("pages")->count($selectors.",manufacturer=$manufacturerItem"); // if I have cars with this manufacturer I'm do something if($carsInManifacturerCount > 0 ){ $resultManifacturerList = new StdClass(); $resultManifacturerList->id = $manufacturerItem->id; $resultManifacturerList->title = $manufacturerItem->title; $resultManifacturerList->count = $carsInManifacturerCount; $marksListArray[] = $resultMarkList; } } So here's my question, is there a more correct way to get all the Manufacturer without brute force in the same way as the SQL query given? Thanks!
×
×
  • Create New...