I have a bunch of data in array without sorting, i need to categorize the data into set and display to the public. This is how the data loop without categorisation.
foreach ($info as $i){
if ($i->metadataKey==1018){
echo $i->businessId . " - " . $i->businessName . " - " . $i->metadataValue;
}
if ($i->metadataKey==1021){
echo ", " . $i->metadataValue;
echo "<br/>";
}
}
it's a joined table and one business having numbers of metadata (associated by metadataKey and metadataValue). The following is the code i getting data from database.
$info = DB::table('business')
->leftJoin('business_meta', 'business.Id', '=', 'business_meta.businessId')
->get();
Or you may reference the following table
Business
- id
- business name
Business_meta
- metadatakey
- metadatavalue
- businessId
one business will have couple of business meta, 1018 is state and 1021 is country
I need to assorciate it into sort array or some pattern of data to display it according to "state, country" on the public site.
Which mean, it may be something like
California, US
- Business 1
- Business 2
Texas, US
- Business 3
Please advice how can i make it. Thanks.