Please help me figure this one out as I am completely new to PHP and defiantly not going to win any trophies in coding efficiency.
I am pulling my CastingCartTalentID from WordPress and then using that ID to look up a category in another table in WordPress. All CastingCartTalentID's are returned just fine, but since my Categories are being looked up within the nested foreach loop, I end up with duplicated Categories:-( The Categories are finally assigned to buttons in HTML, but I don't want to have duplicated buttons on the page.
$myTalentID = $wpdb->get_results("SELECT CastingCartTalentID FROM ". table_agency_castingcart ." WHERE CastingJobID = '$mycustomID'");
foreach ($myTalentID as $obj){
$myID = $obj->CastingCartTalentID;
$mySort = $wpdb->get_results("SELECT DISTINCT B1.ProfileCustomValue FROM ". table_agency_customfield_mux ." B1, ". table_agency_customfields ." A1 WHERE B1.ProfileID = '$myID' AND A1.ProfileCustomTitle = 'Category' AND A1.ProfileCustomID = B1.ProfileCustomID");
foreach ($mySort as $obj){
$myCat = $obj->ProfileCustomValue;
echo "<td><button class=\"filter\" data-filter=\".category- $myCat\">$myCat</button></td>";
}}
When I print_r my $mySort I get the following:
Array ( [0] => stdClass Object ( [ProfileCustomValue] => B ) )
Array ( [0] => stdClass Object ( [ProfileCustomValue] => A ) )
Array ( [0] => stdClass Object ( [ProfileCustomValue] => C ) )
Array ( [0] => stdClass Object ( [ProfileCustomValue] => B ) )
I have tried using array_unique but that dosnt help me. Is there another way to solve this? or is there a solution to remove duplicates?
Please any help is appreciated