I'm trying to fetch query results from Joomla MySQL database in a Joomla page. The print_r
is returning proper results which the db connection is proper. But I'm not able to display the data that has been fetched.
Here's the result that I'm getting at the moment for print_r:
mysqli_result Object (
[current_field] => 0
[field_count] => 2
[lengths] => [num_rows] => 2 [type] => 0
)
Here's the code that I'm using:
{source}
<script language="javascript" type="text/javascript">
</script>
<?php
// init Joomla Framework
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');
// DBQuery
$database =& JFactory::getDBO();
$query = "SELECT city_id, city_name FROM indytoad_city;";
$database->setQuery($query);
$result = $database->query();
print_r($result);
?>
{/source}
Please let me know how and where and what I need to amend in order to display the query results.