1

I am working with codeigniter and i want to fetch recods as "two arrays" based on condition (FilterType='Tag',FilterType='Merchant')

Here is my table "filterproducts"

id          FilterType          CategoryUrl
1           Tag                 abc
2           Tag                 xyz
3           Merchant            abc
4           Merchant            abc

Here is my current code which is giving me multidimenional array

function SearctRecords()
 {
        $this->db->select("*")
            ->from("filterproducts  fp")
            ->join("filterid fi", "fp.FilterType=fi.name")
            ->where("fp.CategoryUrl", $CategoryUrl);
            $query = $this->db->get();  
            $result = $query->result_array();
            return $result;
}

Here is my controller

function SearchFilterProducts()
{
        $users['data'] = $this->Customer_model->SearctRecords($CategoryUrl);
        $responseJSON = array("Status" => $status, "data" => $users['data']);
             header("content-type:application/json");
             $response = json_encode($responseJSON);
             echo $response;
}
Amit
  • 11
  • 1

1 Answers1

0

I would recommend to sort using existing DB sorting methods. Usually will perform better than custom PHP function.

I you still want to sort your multidimensional result, consider using usort.

function custom_super_comparator($a, $b) {
    //custom comparison
}

usort($response, "custom_super_comparator");

Check this good answer on this topic: Sort array of objects by object fields

offtopic, SearctRecords is missing the argument

SearctRecords($CategoryUrl) {
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pau Seglar
  • 66
  • 4