The result stored in $g is 1 and 2. The following code I’ve written below, my $array['music'] stores only the last element that is 2. But what I want is to execute my sql query 2 times under foreach and match the value of $g which is 1 and 2 with mu_id (mu_id is the column name from another table music) and store all the rows data of row 1 and 2 in to $array['music'].
It is storing only for the second row (2) not for 1 or it is overwriting it when it is executing for the second time inside loop. If there is any logic to make it work then please let me know.
foreach($genre as $g)
{
echo $g;
echo "<br>";
$array['music'] = $m -> where('mu_id', $g ) -> get();
}
You’re redeclaring the entire array each time rather than adding to it, use this instead:
Or even better, less queries: