Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Drupal中的自定义块中显示SQL互操作_Php_Sql_Drupal_Block - Fatal编程技术网

Php 在Drupal中的自定义块中显示SQL互操作

Php 在Drupal中的自定义块中显示SQL互操作,php,sql,drupal,block,Php,Sql,Drupal,Block,我在尝试显示以下查询的结果时遇到问题: SELECT COUNT(`entity_id` ) icount, `field_tags_tid`, `taxonomy_term_data`.`name` FROM `field_data_field_tags` INNER JOIN `taxonomy_term_data` ON `taxonomy_term_data`.`tid`=`field_data_field_tags`.`field_tags_tid

我在尝试显示以下查询的结果时遇到问题:

    SELECT COUNT(`entity_id` ) icount, `field_tags_tid`, `taxonomy_term_data`.`name`
    FROM  `field_data_field_tags` 
    INNER JOIN `taxonomy_term_data` 
    ON `taxonomy_term_data`.`tid`=`field_data_field_tags`.`field_tags_tid`
    GROUP BY `field_tags_tid`
    ORDER BY icount DESC 
    LIMIT 0 , 30
在Drupal中的自定义块中

这是my_tags.module文件:

    <?php
    function my_tags_block_info() {
       $blocks = array();

      $blocks['my_first_block'] = array(
        'info' => t('My custom block'),
        // DRUPAL_CACHE_PER_ROLE will be assumed.
      );

      return $blocks;
    }


    function my_tags_block_view($delta = '') {
     if (arg(0) == 'node' && is_numeric(arg(1))) {
        $nid = arg(1);
      };
      $block = array();
      switch ($delta) {
        case 'my_first_block':
          $result = db_query('SELECT COUNT(`entity_id` ) icount, `field_tags_tid`,         `taxonomy_term_data`.`name`
            FROM  `field_data_field_tags` 
            INNER JOIN `taxonomy_term_data` 
    ON `taxonomy_term_data`.`tid`=`field_data_field_tags`.`field_tags_tid`
    GROUP BY `field_tags_tid`
    ORDER BY icount DESC 
    LIMIT 0 , 10');
  $list = array(
    '#theme' => 'links',
    '#links' => array(),

  );
  foreach ($result as $record) {
    $list['#links'][] = array('title' => $record->name , 'name' => $record->icount);
  }
  $block['subject'] = t('Popular tags');
  $block['content'] = $list;
  break;
      }

      return $block;
    }

    ?>
因此,它只显示“name”字段,但我需要和“icount”字段。
谢谢。

刚才用这种方式解决了我的问题:

  function my_tags_block_view($delta = '') {

    $block = array();
    switch ($delta) {
      case 'my_first_block':
        $result = db_query('SELECT COUNT(`entity_id` ) icount, `field_tags_tid`,             `taxonomy_term_data`.`name`, `revision_id`
    FROM  `field_data_field_tags` 
    INNER JOIN `taxonomy_term_data` 
    ON `taxonomy_term_data`.`tid`=`field_data_field_tags`.`field_tags_tid`
    GROUP BY `field_tags_tid`
    ORDER BY icount DESC 
    LIMIT 0 , 10');


  foreach ($result as $record) {

    $list[] = l($record->name, 'taxonomy/term/'.$record->field_tags_tid);

  }
  dpm($list);

  $block['subject'] = t('Popular tags');
  $block['content'] = theme('item_list', array('items' => $list));;
  break;
    }