Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to retrieve data from single and multiple tables in Joomla?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 304
    Comment on it

    Retrieving data from Single table:

    // Getting db connection.
    $db = JFactory::getDbo();
    
    // Create a new query object.
    $query = $db->getQuery(true);
    
    $query->select('*');
    $query->from($db->quoteName('#__tablename')); // table name without prefix
    $query->order('\'ASC\'');
    $query->setLimit('10');
    
    // Reset the query
    $db->setQuery($query);
    
    // Load the results
    $results = $db->loadObjectList();
    
    

    Retrieving data from multiple tables(Using Joins):

    // 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();
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: