如何在单循环中创建此代码?从两张桌子中选出一张!
<?
$items = Array();
$kate=mysql_query("select category_id from movies_cat where movie_id='$ids'");
while($cat=mysql_fetch_array($kate))
{
$kate2=mysql_query("select name_cat from categories where id='$cat[category_id]'");
while($cat2=mysql_fetch_array($kate2))
{
$items[] = $cat2['name_cat'];
}
}
echo implode(",", $items);
?>
答案 0 :(得分:0)
查询应该是SELECT category_id, name_cat from movies_cat m join categories c where m.category_id = c.id and movie_id='$ids'";
试试这个。