anuruddhika
anuruddhika

Reputation: 1559

How to get article title where category id=8 in joomala

I tried to get articles titles where category id = 8.

here is the code i used.

$catID = 8;
$db = JFactory::getDBO();
$db->setQuery("SELECT title FROM #__content WHERE catid = ".$catID);
$catDesc = $db->loadResult();
echo $catDesc;

it display only one title which category id=8.

i want to display all the titles which category id = 8.

Upvotes: 0

Views: 60

Answers (1)

Rahul Kaushik
Rahul Kaushik

Reputation: 1464

Update your code as below:

$catID = 8;
$db = JFactory::getDBO();
$db->setQuery("SELECT title FROM #__content WHERE catid = ".$catID);
$catDesc = $db->loadObjectList();

var_dump($catDesc);

Use loadResult() when you expect just a single value back from your database query.

loadObjectList() returns an indexed array of PHP objects from the table records returned by the query.

Upvotes: 2

Related Questions