When writing a Joomla module or component, you can access the database with the JDatabase option.

If you have to make a query that uses both 'where' and 'and', for instance you have to make a selection that has 2 variables, you can do this in the following manner:

$db = JFactory::getDbo();
$query = $db -> getQuery(true);
$query -> SELECT($db -> quoteName(array('id','item_body', 'item_extra_varchar1', 'item_extra_varchar2', 'date_created','item_extra_varchar3')));
$query -> FROM ($db -> quoteName('#__jne_items'));
$query -> ORDER ('id DESC');
$query -> WHERE ($db -> quoteName('asset_id')."=".$contentid);
$query -> WHERE ($db -> quoteName('item_status')."=".$commentstatus);
$query -> setlimit(50);

// Prepare the query
$results = $db -> loadObjectList();

Using 2 time the 'where' option builds the query like this: 'where asset_id=12 and item_status=1'. Using the data you get from the database goes like this

foreach($results as $row){
echo $row->item_body;}

Happy coding!

Share this page