嗨,我坚持使用这段代码,请查看:
我的表sql:
视频表
id_video id_kategori content1 content2 ....
2 5 ...
3 6 ...
artikel表
id_artikel id_kategori content1 content2 ...
3 5 ...
5 6 ...
kategori表
id_kategori nama_kategori
4 berita
5 videophp
6 videohtml
源代码:
$query = mysqli_query(DB::connect(),"SELECT * FROM `kategori`");
while($row = mysqli_fetch_row($query)){
?>
<ul>
<?php
$jml = mysqli_fetch_row(mysqli_query(DB::connect(),"SELECT (SELECT COUNT(\*) FROM `artikel` WHERE `id_kategori`='$row[0]') as first,(SELECT COUNT(\*) FROM `video` WHERE `id_kategori`='$row[0]') as second FROM dual"))[0];
?>
<li><a href='<?php echo substr($row[1],0,5) == "video" ? "video" : "artikel"; ?>.php?kategori="<?php echo $row[0]; ?>"'><?php echo $row[1].'('.$jml.')'; ?></a></li>
</ul>
<?php
}
?>
它返回:
olahraga(17)
TEKNOLOGI(2)
Politik(6)
每日新闻(2)
视频php(0)
视频html(0)
除了视频表之外的一切都很好
只需1张表的简单计数就可以了 SELECT()FROMvideo
WHERE id_kategori
= $ row [0] artikel
WHERE id_kategori
= $ row [0]
所以我的代码有什么不对,有谁知道?拜托,谢谢