problema funzione banale php

2 contenuti / 0 new
Ultimo contenuto
problema funzione banale php

Salve ragazzi, sono un neofita di drupal e php e sto cercando di fare un modulo che mi visualizzi l'ip del utente connesso e la lista dei suoi articoli, ma qualcosa sbaglio in questa funzione:
function moduloip_block_view($delta = '') {
global $user;
$account = $user;
$block['content'] = t('Ciao @user con IP @host',array(
'@user' => format_username($user),
'@host' => $account->hostname
));
$block['content'].=t('Tuoi post:');
$query = db_select('node', 'n');
$query->join('users', 'u', 'n.uid = u.uid'); //JOIN node with users
$query->fields('n',array('title'));//SELECT the fields from node
$query->condition('u.name',$user,'=');

$result = $query->execute();

foreach($result as $node) {
$items[] = array(
'data' => t($node->title)
);
}

$block['content'] .= theme('item_list', array(
'items' => $items
));

return $block;
}

Cosa sbaglio? Grazie mille

Drupal Version:

Ciao, forse l'errore è nel tuo ciclo for... ma per la lista articoli dell'utente farei cosi:

function MYMODULE_list_page() {
  $output = '';
  $list = array();
  $list['type'] = 'ul';
  $list['title'] = 'List of nodes';
  $list['attributes'] = array('class' => array('list-of-nodes'));
  $list['items'] = array();
  $results = db_query("SELECT b.bid,n.nid AS nid,n.vid,n.type,n.language,n.title AS node_title,n.changed FROM {node} n INNER JOIN {users} u ON n.uid = u.uid");
  foreach ($results as $record) {
    $obj = db_query("SELECT menu_name FROM {menu_links} WHERE link_path=:link_path", array(':link_path' => 'node/' . $record->nid))->fetchObject();
    $menu_name = isset($obj->menu_name) ? '[Menu ' . $obj->menu_name . ']' : '';
    $list['items'][] = date('d-m-Y H:i', $record->changed) . ' ' . $record->type . ' ' . l($record->nid . ' ' . $record->node_title, 'node/' . $record->nid) ;
  }
  $output = theme('item_list', $list);
  return $output;
}

Nel blocck invece metterei:
function MYMODULE_block_view($delta = '') {
  global $user;
  $block = array();
  switch ($delta) {
    case 'latestarticles':
        $block['subject'] = 'Articles';
        $block['content'] = MYMODULE_list_page();
        return $block;
     break;
  }
}

Per l'inidrizzo ip non lo so non potresti usare https://www.drupal.org/project/smart_ip ?