Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.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
Sql Drupal:显示每个用户的贡献(发布内容)列表_Sql_Drupal_Drupal 6_Drupal Views - Fatal编程技术网

Sql Drupal:显示每个用户的贡献(发布内容)列表

Sql Drupal:显示每个用户的贡献(发布内容)列表,sql,drupal,drupal-6,drupal-views,Sql,Drupal,Drupal 6,Drupal Views,我正在寻找一种在会员资料页面上显示某些内容类型的投稿数量的方法。基本上,它必须显示如下内容: 博客(10) 第(10)条 问题(19) 评论(30) 小贴士(3) 我安装了一些不同的模块(如“用户统计”),我认为这些模块可以帮助我,但没有成功 我想知道,通过使用uid将其硬编码到我的模板文件中,并使用我想要显示的内容类型运行一些查询,是否最简单,但我也不确定如何做到这一点 如有任何帮助或建议,将不胜感激 真诚的 -梅斯蒂卡 编辑: 我找到了一个解决方案,可以通过对每种内容类型的查询手动完成,但我

我正在寻找一种在会员资料页面上显示某些内容类型的投稿数量的方法。基本上,它必须显示如下内容:

博客(10)
第(10)条
问题(19)
评论(30)
小贴士(3)

我安装了一些不同的模块(如“用户统计”),我认为这些模块可以帮助我,但没有成功

我想知道,通过使用uid将其硬编码到我的模板文件中,并使用我想要显示的内容类型运行一些查询,是否最简单,但我也不确定如何做到这一点

如有任何帮助或建议,将不胜感激

真诚的 -梅斯蒂卡

编辑:
我找到了一个解决方案,可以通过对每种内容类型的查询手动完成,但我仍然对一个更优雅、更流畅的解决方案非常感兴趣

我使用以下代码:

global $user;
$userid = $user->uid;
$blog_count  = db_result(db_query("SELECT COUNT(0) AS num FROM {node} n where n.type = 'blog' AND status = 1 AND n.uid = {$userid}"));

考虑到您的简单需求,以及您手头有SQL语句的事实,我建议您使用它。没有理由为了一个查询而向站点添加另一个模块并影响其性能


也就是说,从“关注点分离”的角度来看,您不应该只是将此SQL放在模板中。相反,您应该使用
template.php
文件中的预处理函数将其结果添加到可用变量列表中,将其范围限制在您需要的地方,这样您就不会在任何页面上运行此数据库查询,而是在相应的配置文件页面上运行此查询。

如果您使用的是核心配置文件模块,你可以用下面的方法。它将显示由正在查看其配置文件的用户创建的节点。另外一个好处是,它只需要执行一个自定义数据库查询

将此代码段插入主题文件夹中的
template.php
,并将“THEMENAME”更改为主题名称:

function THEMENAME_preprocess_user_profile(&$variables) {
  // Information about user profile being viewed
  $account = $variables['account'];

  // Get info on all content types
  $content_types = node_get_types('names');

  // Get node counts for all content types for current user
  $stats = array();
  $node_counts = db_query('SELECT type, COUNT(type) AS num FROM {node} WHERE status = 1 AND uid = %d GROUP BY type', $account->uid);
  while ($row = db_fetch_array($node_counts)) {
    $stats[] = array(
      'name' => $content_types[$row['type']],
      'type' => $row['type'],
      'num' => $row['num'],
    );
  }
  $variables['node_stats'] = $stats;
}
现在,在
user profile.tpl.php
中可以添加类似的内容:

// If user has created content, display stats
<?php if (count($node_stats) > 0): ?>

  // For each content type, display a DIV with name and number of nodes
  <?php foreach ($node_stats as $value): ?>
    <div><?php print $value['name']; ?> (<?php print $value['num']; ?>)</div>
  <?php endforeach; ?>

// Message to show for user that hasn't created any content
<?php else: ?>
  <?php print $account->name; ?> has not created any content.
<?php endif; ?>
//如果用户已创建内容,则显示统计信息
//对于每种内容类型,显示一个包含名称和节点数的DIV
()
//为尚未创建任何内容的用户显示的消息
尚未创建任何内容。
这只是你能做什么的一般想法。您还可以为查找/显示的内容类型添加限制,检查用户查看这些统计数据的权限,使用CSS更改统计数据的外观,等等

如果正在使用,则可以使用
mename\u preprocess\u node()
,并在执行此代码之前检查该节点是否为概要文件节点