Way to use Joomla loadAssoc


mysql_fetch_assoc is the native PHP MySQL function to fetch a result row as an associative array. Joomla! has it’s own database abstraction class that does this job — loadAssoc.

Below is an example of the using loadAssoc to fetch a result row from content table and show the individual selected field results:

$db = JFactory::getDBO();
$query = "SELECT * FROM #__content WHERE
title='Overview'";
$db->setQuery($query);
$article_row = $db->loadAssoc();
echo $article_row['introtext']."—".$article_row['publish_up'];

The output will the the intro text of the article with the title Overview and followed by published date and time.

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

  1. #1 by gracie114 on June 3, 2008 - 9:27 am

    i think many people still prefer the default way PHP handles database, there are just too many custom database libraries.

  2. #2 by Edilson on January 7, 2009 - 5:05 am

    Otima materia
    Olha para quem esta comensando com O joomla, aqui vai a dica de um seti onde tem mais de 30 videos tutorias destinado ao Joomla.

    http://www.joomlamazonia.com.br/

(will not be published)