joomla 2.5, how do I retrieve data from the database?


i want to show data from database on my module front page. To retrive data from database i write this code in helper.php

public static function getdb($params)
// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value',   'ordering')));
$query->where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'custom.%\''));
$query->order('ordering ASC');

// Reset the query using our newly populated query object.

// Load the results as a list of stdClass objects (see later for more options on    retrieving data).
$results = $db->loadObjectList();
foreach($results as $value)
echo $value;

and my helloworld.php file put this code


// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );

$hello = modHelloWorldHelper::getdb( $params );

require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );

and tmpl/default.php file code is

<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<?php echo $hello; ?>

but results is blank. nothing show in module page. how to i get data from database? how is the right format to get data from database?

$db->loadObjectList() loads an array of objects, which cannot be echo'ed as a string, try to

foreach($results as $value)


foreach($results as $value)
  echo $value->user_id;