Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. /**
  2. *  Return some simple calculated stats
  3. */
  4. function samsungblog_helper_simplestats() {
  5.   /* First, we want some user stats */
  6.   $sql_totalusers = "select count(users.status) from users users where status = 1;";
  7.   $totalusers = db_result(db_query($sql_totalusers));
  8.   $output = "<h4>" . t("User stats") . "</h4>\n" ;
  9.  
  10.   /* This is a more optimised query */
  11.   $sql_users = "select  r.name, count(ur.uid) user_cnt from role r inner join users_roles ur on r.rid = ur.rid group by r.name;";
  12.   $result_users = db_query($sql_users);
  13.  
  14.   $output .= "<ul>\n";
  15.   while ($row = db_fetch_array($result_users)) {
  16.     $output .= "<li>" . $row['user_cnt'] . "&nbsp;" . t("users has role ") . "<em>" . $row['name'] . "</em></li>\n";
  17.   }
  18.   $output .= "</ul>\n";
  19.   $output .= "<p><span class='simpletotal'>" . $totalusers . "</span> " . t("total active users") . "</p>\n";
  20.  
  21.   $output .= "<br />";
  22.    
  23.   /* Now, some content stats */
  24.   $output .= "<h4>" . t("Content stats") . "</h4>\n";
  25.   $sql_nodes = "select type,count(nid) as total from node where status=1 group by type;";
  26.   $result_nodes = db_query($sql_nodes);
  27.  
  28.   $total_nodes = 0;
  29.   $output .= "<ul>\n";
  30.   while ($row = db_fetch_array($result_nodes)) {
  31.     $total_nodes = $total_nodes + $row['total'];
  32.     $output .= "<li>" . $row['total'] . "&nbsp;" . t('published nodes of type ') . "<em>" . $row['type'] . "</em></li>\n";
  33.   }
  34.   $output .= "</ul>\n";
  35.  
  36.   $output .= "<p><span class='simpletotal'>" . $total_nodes . "</span> " . t("total published nodes") . "</p>\n";
  37.  
  38.   /* Return the content */
  39.   return $output;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement