Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Methods to display Query Results in Joomla

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 663
    Comment on it

    There are various methods used in Joomla to display query results according to the requirement. They are as follows:

    Single Value Result :

    • loadResult():
      loadResult() method is used when a database query returns a single value. It is basically used with count query.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('COUNT(*)');
      $query->from($db->quoteName('#__yourtablename'));
      $query->where($db->quoteName('columnname')." = ".$db->quote($value));
      $db->setQuery($query);
      $count = $db->loadResult();

    Single Row Results :

    • loadRow():
      loadRow() method returns a single record in indexed array form.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      $query->where($db->quoteName('columnname')." = ".$db->quote($value));
      $db->setQuery($query);
      $count = $db->loadRow();
    • loadAssoc():
      loadAssoc() method returns a single record in associated array form.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      $query->where($db->quoteName('columnname')." = ".$db->quote($value));
      $db->setQuery($query);
      $count = $db->loadAssoc();
    • loadObject()
      loadObject() method returns a single record in PHP object form.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      $query->where($db->quoteName('columnname')." = ".$db->quote($value));
      $db->setQuery($query);
      $count = $db->loadObject();

    Single Column Results:

    • loadColumn():
      loadColumn() method returns a single column in indexed array form.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      $query->where($db->quoteName('columnname')." = ".$db->quote($value));
      $db->setQuery($query);
      $count = $db->loadColumn();

    Multi-Row Results:

    • loadRowList():
      loadRowList() method is used when the database query returns all the records of the table. It returns indexed array of indexed arrays.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      // Reset the query using our newly populated query object.
      $db->setQuery($query);
      $count = $db->loadRowList();
    • loadAssocList():
      loadAssocList() method is used when the database query returns all the records of the table. It returns indexed array of associated arrays.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      // Reset the query using our newly populated query object.
      $db->setQuery($query);
      $count = $db->loadRowList();
    • loadObjectList():
      loadObjectList() method is used when the database query returns all the records of the table. It returns indexed array of PHP objects.
      For example:
      $db = JFactory::getDbo();
      $query = $db->getQuery(true);
      $query->select('*');
      $query->from($db->quoteName('#__yourtablename'));
      // Reset the query using our newly populated query object.
      $db->setQuery($query);
      $count = $db->loadRowList();

 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: