dongwujie7477 2015-02-18 21:59
浏览 25

循环重复

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装