0
<?php
/**
Provides a block with query and store in database
*/
/**
* Implementation of hook_help().
*/
function demo_help($path,$args)
{
if($path=='admin/help#demo')
{
return t('To use this module, go to block page and turn on the       demo');
}
}

function demo_block_info()
{
$blocks=array();
$blocks['demo_member']=array(
'info'=>t('Demo member'),
'cache'=>DRUPAL_NO_CACHE,
);
return $blocks;
}

/**
* Implements hook_block_view().
*/
function demo_block_view($name)
{
if($name=='demo_member')
{
//$format2 = 'g:i a';
$content=db_query("SELECT entity_id FROM     {field_data_field_category_status}")->fetchField();
            $content.='';
            $block=array(
            'subject'=>t('Member'),
            'content'=>$content,
            );
            return $block;
    }

}
?>

i need to display 3 records by fetching array(.module file) i am getting single record: Member 1 i should get below Member 1 2 3

1 Answer 1

2

Change

$content=db_query("SELECT entity_id FROM {field_data_field_category_status}")->fetchField();
$content.='';

to

$records = db_query("SELECT entity_id FROM {field_data_field_category_status}")->fetchCol();
$content = implode('<br />', $records);

At the moment you're just getting the first record from the result set, not all of them.

As a side note, going directly into field tables isn't the best idea. Have a look at EntityFieldQuery for an alternative.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.