I’m trying to create a custom module that implements a block to display something I haven’t been able to do with the Views 2 module.
I’ve tried to look at some guides and tutorials, but I haven’t got any result yet.
I can print out the first SELECT attribute in the first row. The first row make sense since I don’t loop through it but still I’m confused on how to do the rest.
function sn_most_contributed_block($op='list', $delta=0) {
if ($op == "list") {
// Generate listing of blocks from this module, for the admin/block page
$block = array();
$block[0]["info"] = t('Most Contribution this week (custom module');
return $block;
}
elseif ($op == 'view') {
$mce = db_result(
db_query("SELECT node.uid, COUNT(nid), users.picture AS users_picture, users.uid AS users_uid, users.name AS users_name, users.mail AS users_mail FROM node node INNER JOIN users users ON node.uid = users.uid WHERE (node.type IN ('leads', 'qa', 'qa_comments', 'til_salg', 'tips_tricks')) AND node.created >= UNIX_TIMESTAMP( CURDATE( ) - INTERVAL 1 WEEK ) AND node.created <= UNIX_TIMESTAMP( CURDATE( ) + INTERVAL 1 DAY ) GROUP BY uid ORDER BY COUNT(nid) DESC LIMIT 0 , 5")
);
$block_content .= "Most contributed members are: " . $mce';
$block_content .= "<div class='author picture profile_image'>In here should be the user image</div>";
$block_content .= "<div id='username'>In here should be the username</div>";
if ($block_content == '') {
$block['subject'] = 'contribution test';
$block['content'] = 'yay';
return $block;
}
else {
// set up the block
$block = array();
$block['subject'] = 'Most contribution this week';
$block['content'] = $block_content;
return $block;
}
}
}
I’ve tested my query in the database environment for my Drupal site and it works and print everything it should out correctly.
For looping the query, I tried this code with no result.
while ($contriUser = db_fetch_object($mce)) {
$contriUser [] = $contriUser->uid;
}
I have also tried the following code.
while ($contriUser = db_fetch_object($mce)) {
var_dump($contriUser);
}
Any help on how to solve this or if someone has an alternative solution to get the most contributing members last seven days it would be much appreciated.
"Most contributed members are: " . $mce';
. The'
at the end is wrong. But I think that's not the actual problem.