Find us on facebook

Jun 16, 2015

Selecting data using JDatabase

Select query
Method 1 : 
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('fname', 'lname')));
$query->from($db->quoteName('#__students'));
$db->setQuery($query);
$row = $db->loadAssocList();

Method 2 : 
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('fname', 'lname')));
$query->from($db->quoteName('#__students'));
$db->setQuery($query);
$row = $db->loadRowList();
return $row[0][0];

Access individual values:

Method 1 
echo  $row[1]['lname'];

Method 2 : 
echo  $row[1][1];


No comments:

Post a Comment