我有这两张桌子..
表1"孩子"
表2"收藏夹"
我想要的是在表格中显示它..
我该怎么做?
这是我试过的代码
$result = mysql_query("SELECT kids.*, favorites.* from kids INNER JOIN favorites ON kids.kids=favorites.kids");
$number='1';if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result))
{
$idnumber=$row['kids'];
?>
<td class="centered"><?php echo $number;?></td>
<td class="centered hidden"><?php echo $idnumber;?></td>
<td class="centered hidden"><?php echo $row['favorites'];?></td>
<?php
}
++$number;
}
?>
`
答案 0 :(得分:2)
尝试:
SELECT a.int,a.kids,b.kids,GROUP_CONCAT(b.favourite) from kids a, favourites b where a.kids = b.kids
这应该有效
答案 1 :(得分:2)
尝试:
SELECT
kids.int as '#', kids.kids as 'Kids',
GROUP_CONCAT(favorites.favr) as 'Favourites'
FROM kids
JOIN favorites on kids.kids = favorites.kids
GROUP BY favorites.kids
答案 2 :(得分:0)
SELECT kids.kids, favorites.favorites
FROM kids
INNER JOIN favorites
ON kids.kids=favorites.kids;
是一个示例,但我建议您更多地了解SQL连接。
答案 3 :(得分:0)
这就是你想要的 -
SELECT a.int as int, a.kids as Kids, GROUP_CONCAT(b.favourite separator ',') as Favourites
FROM kids a, favourites b WHERE a.kids = b.kids