我使用数据库字段“tag
”,“tag_url
”和“tag_weight
”创建了一个小模块,并填写了一个表单。
现在我想在自定义块中输出数据库值,但我不知道如何以正确的方式创建它: - /
/**
* Implements hook_block_info().
*
* This hook declares what blocks are provided by the module.
*/
function myModule_block_info() {
$blocks['example_uppercase'] = array(
// info: The name of the block.
'info' => t('Example: uppercase this please'),
'status' => TRUE,
);
return $blocks;
}
/**
* Implements hook_block_view().
*
* This hook generates the contents of the blocks themselves.
*/
function myModule_block_view($delta = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'example_uppercase':
//Select items from DB
$result = db_select('myModule','ht')
->fields('ht',array('tag','tag_url','tag_weight'))
->execute();
**$block['content'] = foreach($result as $value) { echo $value->tag; }**
break;
}
return $block;
}
当我尝试这样做时,我得到:
PHP Parse错误:语法错误,意外的T_FOREACH in 第49行的/.module
如何将数据库值打印到块?