Posted by hmdnawaz on February 4, 2011 at 7:18am
Hi i want to create a block using hook_block. Which will display top posters of discussion forums.
Any one who can write code for me? Thanks
Hi i want to create a block using hook_block. Which will display top posters of discussion forums.
Any one who can write code for me? Thanks
Comments
hook_block
<?php/**
* Implementation of hook_block().
*/
function yourmodule_block($op = 'list', $delta = 0) {
$block = array();
switch ($op) {
case 'list':
$block[0]['info'] = t('Set a text/title/subject which show in block list');
return $block;
case 'view':
switch ($delta) {
case 0:
$block['subject'] = t('Sidebar Links');
$block['content'] = "super weak";
break;
case 1:
$block['subject'] = t('Your block title');
$block['content'] = "Your Block content";
break;
}
return $block;
}
} // end function fightfi_block
?>
skype #id :
asghar.khan5
contact# +923326684082
I want to retrieve users
I want to retrieve users from the database who are the top posters in forum discussion but using nodeapi or node_load function.
Ahmad Nawaz
This would get top 5 posters
This would get top 5 posters and top 5 commenters and table them. You'd probably want to add some lime limit, too.
<?php
function top_forum_whores() {
//Top posters.
$header = array('Name', 'Posts');
$table = array();
$sql = db_query("SELECT u.name AS name, COUNT(n.uid) AS count FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE n.type = 'forum' AND n.uid <> 0 GROUP BY n.uid LIMIT 5");
while ($row = db_fetch_object($sql)) {
$table[] = array($row->name, $row->count);
}
$output .= '<h3>' . 'Top posters' . '</h3>';
$output .= theme_table($header, $table);
//Top commenters.
$header = array('Name', 'Comments');
$table = array();
$sql = db_query("SELECT u.name AS name, COUNT(c.uid) AS count FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.nid IN (SELECT nid FROM node WHERE type = 'forum') AND c.uid <> 0 GROUP BY c.uid LIMIT 5");
while ($row = db_fetch_object($sql)) {
$table[] = array($row->name, $row->count);
}
$output .= '<h3>' . 'Top commenters' . '</h3>';
$output .= theme_table($header, $table);
return $output;
?>
Within the block, you would use
<?php$block['content'] = top_forum_whores();
?>
Disclaimer: I tested only the SQL part, so there may be some silly mistake within PHP part.
ᚘ ᚘ ᚘ
BUt Without queries
But i want top 5 posters without using sql queries. Using nodeapi or Variable_get() or any other method but not with queries.
Ahmad Nawaz