我想要的结果:
campaign 1
offer 1.1
offer 1.2
offer 1.3
(and so forth)
campaign 2
offer 2.1
offer 2.2
offer 2.3
(and so forth)
这些是我的表:
campaign (tablename)
campaign_id (used)
campaign_name
offer (tablename)
offer_id
offer_parentid (uses category_id find which category the item is supposed to be paired
with.)
offer_name
我几乎没有使用两张桌子的经验,但我发现它对这种事情很有用。我的问题是我已经尝试了我所知道的 php 的各个方面,但我无法得到我想要的结果。这是我经过几个小时的血汗和泪水后的最终结果:
$get_campaign = mysql_query("SELECT * FROM campaign ORDER BY campaign_id DESC")
or die(mysql_error());
$get_offers = mysql_query("SELECT * FROM offers JOIN campaign ON offers.offer_parentid=campaign.campaign_id ORDER BY campaign_id DESC ")
or die(mysql_error());
while($row = mysql_fetch_array($get_campaign)){
echo $row['campaign_name']."</br>";
while($row = mysql_fetch_assoc($get_offers)){
echo $row['offer_name']."</br>";
}
}
结果变为:
Campaign 1
offer 1.1
offer 1.2
offer 2.1
offer 2.2
campaign 2
感谢我能得到的任何帮助