我必须按照标题在查询中订购文章。
我的查询:
<?php
$catId = 43;
$query = "SELECT * FROM #__content WHERE catid ='" . $catId . "'";
$db = JFactory::getDBO();
$db->setQuery($query);
$articles = $db->loadObjectList();
foreach($articles as $article){
}
?>
答案 0 :(得分:0)
更改$ query-&gt; order('id DESC');到
$ query-&gt; order('title DESC');
如果你想要或ASC:)
答案 1 :(得分:0)
2个选项,第一个在游览请求中按标题添加顺序:
$query = "SELECT * FROM #__content WHERE catid ='" . $catId . "' order by title asc";
第二个,更好的是,您使用joomla查询构建器:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')->from('#__content')->where('catid = '.$catId)->order('title asc');
$db->setQuery($query);