<?php
mysql_select_db($database_dbconnect, $dbconnect);
$query_cats = "SELECT * FROM articles INNER JOIN categories ON articles.category_id = categories.id GROUP BY articles.category_id ORDER BY articles.created DESC LIMIT 0, 6";
$cats = mysql_query($query_cats, $dbconnect) or die(mysql_error());
$row_cats = mysql_fetch_assoc($cats);
$totalRows_cats = mysql_num_rows($cats);
?>
如何使用 php 和 mysql 从每个类别中调用4篇文章。 请帮我处理数据库表和php编码,如下所示:
体育
娱乐
我试试这段代码:
<?php
do {
echo $row_cats['category_name'];
echo $row_cats['title'];
?>
</a></h3>
<?php
echo strip_tags(substr($row_cats['body'],0,100));
?>
...
<a href="article.php?id=<?php echo $row_cats['id']; ?>"> Full story </a>
<ul>
<li><?php echo $row_cats['title']; ?>
</li>
</ul>
<?php
} while ($row_cats = mysql_fetch_assoc($cats));
?>