Sageth
05-29-2007, 07:23 PM
I'm stuck, so I turn to you all for help. Hopefully, someone can tell me what I'm missing. I'm sure it's something silly, but it's been quite a few years since I've coded.
What I'm trying to do is go through my database and get it to add the "rate" field. I've set up the query, but I just can't figure out how to get it to display on the page. The closest I've gotten is when I put it in the foreach, but then it doesn't add (obviously).
I've looked on the web for the past few hours and, while I've found some good information, it's just not clicking in my head.
Here's (a portion of) my code:
global $database;
$count = $params->get( 'count' );
$componentid = $params->get( 'componentid');
$query = "SELECT #__flashgames_stars.*, SUM(rate) as sum,"
.' #__flashgames.title,'
.' #__flashgames.id'
.' FROM #__flashgames_stars INNER JOIN #__flashgames ON'
.' #__flashgames_stars.gid = #__flashgames.id'
.' GROUP BY gid'
.' ORDER BY #__flashgames_stars.rate DESC LIMIT '.$count;
$database->setQuery($query);
$hits = $database->loadObjectList();
// retrieve the rows as objects
foreach ($hits as $hits_row) {
$gid = $hits_row->gid;
$title = $hits_row->title;
$catid = $hits_row->catid;
$rate = $hits_row->rate;
}
echo '<center><a href="'.$mosConfig_live_site.'/index.php?option=com_flashgames&Itemid='.$componen tid.'&task=view&catid='.$catid.'&id='.$gid.'">'.$title.' - '.$rate.' stars</a></center><br />';
What I'm trying to do is go through my database and get it to add the "rate" field. I've set up the query, but I just can't figure out how to get it to display on the page. The closest I've gotten is when I put it in the foreach, but then it doesn't add (obviously).
I've looked on the web for the past few hours and, while I've found some good information, it's just not clicking in my head.
Here's (a portion of) my code:
global $database;
$count = $params->get( 'count' );
$componentid = $params->get( 'componentid');
$query = "SELECT #__flashgames_stars.*, SUM(rate) as sum,"
.' #__flashgames.title,'
.' #__flashgames.id'
.' FROM #__flashgames_stars INNER JOIN #__flashgames ON'
.' #__flashgames_stars.gid = #__flashgames.id'
.' GROUP BY gid'
.' ORDER BY #__flashgames_stars.rate DESC LIMIT '.$count;
$database->setQuery($query);
$hits = $database->loadObjectList();
// retrieve the rows as objects
foreach ($hits as $hits_row) {
$gid = $hits_row->gid;
$title = $hits_row->title;
$catid = $hits_row->catid;
$rate = $hits_row->rate;
}
echo '<center><a href="'.$mosConfig_live_site.'/index.php?option=com_flashgames&Itemid='.$componen tid.'&task=view&catid='.$catid.'&id='.$gid.'">'.$title.' - '.$rate.' stars</a></center><br />';