To select data from one or more tables in Joomla:
Ex:
// Getting db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// give the name of field instead of column name that you want to display in the query given below and tablename instead of table1 and table2
$query
->select(array('a.*', 'b.column_name'))
->from($db->quoteName('#__table1', 'b'))
->join('INNER', $db->quoteName('#__table2', 'a') . ' ON (' . $db->quoteName('a.columnname') . ' = ' . $db->quoteName('b.columname') . ')')
->order($db->quoteName('a.columnname') . ' DESC');
// Reset the query
$db->setQuery($query);
// Load the results
$results = $db->loadObjectList();
Retrieving data in different formats in Joomla:
1. loadResult():
This method is used when your database query returns a single value.
2. loadRow():
Returns a single record as an indexed array form.
3. loadAssoc:
Returns a single row as an associated array format.
4. loadObject:
Returns a single record(row) as an object form.
5. loadColumn:
Returns a single column as an indexed array.
6. loadRowList():
Returns the table record that is returned by the query as an indexed array of indexed arrays.
7. loadAssocList():
Returns the table record that is returned by the query as an indexed array of associated arrays.
8. loadObjectList():
Returns the table record that is returned by the query as an indexed array of PHP objects.
0 Comment(s)