Feb

13

Way to use Joomla loadAssoc

February 13, 2008 |


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.



Similar Posts

Comments

Name (required)

Email (required)

Website

Speak your mind

1 Comment so far

  1. 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.

Sponsors




Links