我是PHP和MySQL的新手。我正在創建自己的小新聞博客。我得顯示我想要的信息,但我想要做的是計算評論的數量。我做了2張桌子,第一張桌子是文章,另一張是評論。我不確定如何解決這個問題。誰能幫忙?2個sql在一個php while循環
$input_now1 = "SELECT blog_entries.id, blog_entries.posted, blog_entries.subject, blog_entries.quicktext
FROM blog_entries
ORDER BY blog_entries.posted DESC
LIMIT 0, 3;";
$result1 = mysql_query($input_now1);
?>
<div id="middle">
<div id="box1">
<?php
while($record1 = mysql_fetch_assoc($result1))
{
?>
<h2 style="padding-top:5px;"><?php echo $record1['subject']; ?></h2>
<div id="header1" style="position:relative;"></div>
<div id="maintext" style="position:relative;">
<p><?php echo $record1['quicktext']; ?></p>
<a href="blog_articles.php?ID=<?php echo $record1["id"];?>">View Article - <?php echo date("D jS F Y g:iA",strtotime($record1["posted"]));?></a>
</div>
<div id="text_footer"></div>
<?php
}
mysql_free_result($result1);
?>
</div>
<?php
include 'include/sidebar.php';
?>
</div>
表1 blog_entries: ID 發佈 主題 體 quicktext
表2 blog_comments: ID blog_id 發佈 名 評論
表1:blog_entries ID 發佈 主題 體 quicktext 表2:blog_comments ID blog_id 發佈 名 評論 – blackbull77 2010-07-14 21:36:49
@ blackbull7:你應該把在原來的問題,更可讀的格式。我更新了我的答案以符合您的模式。 – Borealid 2010-07-14 21:40:08
我更新了問題。如何讓我能夠在php中循環使用或使用其他函數? – blackbull77 2010-07-14 21:57:16