欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

得到 当前视图 current views (view) 的 sql 语句 得到参数 就可以取 views 的任意字段的 任意值 计算总和 求和 sum num 等等 得到条目数 有大用 有大大用 有大大大用


drupal 6   drupal6  d6 中  

function  shipingzhongcustomfour_get_total_field_baomingxuefei_value(){
 $view = views_get_current_view();
 $sql = $view->build_info['query'];
 $args = $view->build_info['query_args'];
 $result = db_query($sql,$args);
 $total_field_baomingxuefei_value = 0;
 while ($obj = db_fetch_object($result)) {
   $total_field_baomingxuefei_value += floatval($obj->node_data_field_xueshenname_field_baomingxuefei_value);
 }
 return "<div class='views_count'><strong>总计报名学费 <font color='red' id='total_field_baomingxuefei_value'>" . $total_field_baomingxuefei_value . "</font> 元</strong></div>";
}




function shipingzhongcustomfour_get_view_rowcount(){

 $view = views_get_current_view();

 $page_total = count($view->result);

 //return "<div class='views_count'><strong>嗯条目数 <font color='red'>" . $page_total . "</font></strong></div>";

 if(isset($view->total_rows)){
   return "<div class='views_count'><strong>条目数 <font color='red'>" . $view->total_rows . "</font></strong></div>";
 } else {
   return "<div class='views_count'><strong>条目数 <font color='red'>" . $page_total . "</font></strong></div>";
 }
}



drupal 7   drupal7  d7 中   方法一

<?php
function custome_twenty_eight_arbitration_get_total_baiban_yongcan_value()
{
  $view = views_get_current_view();
  $result = $view->result;
  $total = 0;
  foreach($result as $key=>$obj)
  {
     $total += intval($obj->field_field_baiban_num[0]['raw']['value']);
  }
  return $total;
}



function custome_twenty_eight_arbitration_get_total_yeban_yongcan_value()
{
  $view = views_get_current_view();
  $result = $view->result;
  $total = 0;
  foreach($result as $key=>$obj)
  {
     $total += intval($obj->field_field_yeban_num[0]['raw']['value']);
  }
  return $total;
}
function custome_twenty_eight_arbitration_get_yooncai_date_value()
{
  $view = views_get_current_view();
  $result = $view->result;

  foreach($result as $key=>$obj)
  {
    //一天是 86,400 秒,用餐时间是明天
     $date = date('Y-m-d',$obj->node_created+86400);
     break;
  }
  return $date;
}

drupal 7   drupal7  d7 中   方法二

function  shipingzhongcustomfour_get_total_field_baomingxuefei_value(){
 $view = views_get_current_view();
 $sql = $view->build_info['query']->__toString();
 $args = $view->build_info['query_args'];
 $result = db_query($sql,$args);
 $total_field_baomingxuefei_value = 0;
 while ($obj = db_fetch_object($result)) {
   $total_field_baomingxuefei_value += floatval($obj->node_data_field_xueshenname_field_baomingxuefei_value);
 }
 return "<div class='views_count'><strong>总计报名学费 <font color='red' id='total_field_baomingxuefei_value'>" . $total_field_baomingxuefei_value . "</font> 元</strong></div>";
}





drupal 7   drupal7  d7 中  方法三

<?php
function
custome_twenty_eight_arbitration_get_total_baiban_yongcan_value()
{
 
$view = views_get_current_view();
 
$e = kprint_r($view,TRUE);
 
print($e); //从 views 中得到 结果 再对结果里面相应的值进行相加,见下图图一
//   $e = kprint_r($view->build_info,TRUE);
//   print($e);
 
$view->execute();
 
$response1 = $view->result;
 
$e = kprint_r($response1,TRUE);
 
print($e);//或者 根据上面三行得到结果,再对结果里面相应的值进行相加,见下图图二
   //.............//这里省略的是相加

 
return "相加后面的结果";
}
图一

image.png


图二

image.png




普通分类: