我在数据库中有一个表“neotheme_blog_post”,那里有很多帖子,现在我想从这个表中获取最近3个帖子并在主页上显示它们:我试图获取数据如下但没有工作:
<?php $connection =
Mage::getSingleton('core/resource')->getConnection('core_read');
$query = "Select * FROM 'neotheme_blog_post'";
$rows = $connection->fetchAll($query);
foreach ($rows as $values) {
echo $name = $values['name'];
}?>
答案 0 :(得分:2)
您可以在这里使用LIMIT。
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$query = "Select * FROM neotheme_blog_post LIMIT 3";
$rows = $connection->fetchAll($query);
foreach ($rows as $values){
echo $name = $values['name'];
}
答案 1 :(得分:1)
在我的情况下,我使用neotheme博客扩展程序获得了最近的三篇帖子:
$connection =
Mage::getSingleton('core/resource')->getConnection('core_read');
$query = "Select * FROM neotheme_blog_post ORDER BY created_at DESC LIMIT 3 ";
$rows = $connection->fetchAll($query);
foreach ($rows as $values) {
$post_titile = $values['cms_identifier'];
echo '<div>';
echo '<h1>' . $name = $values['title'] . '</h1>';
echo $summery = $values['summary'];
echo '<a href="' . $this->getUrl().'blog/'. $post_titile . '">Read More</a>';
echo '</div>';