如果单元格重复,php表添加值

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如果单元格重复,php表添加值脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个wordpress循环恢复这样的表:

如果单元格重复,php表添加值

我想检查名称是否重复自己,如果是,则显示部分值的总和以显示总数.
在我的屏幕截图中,第1行和第3行具有相同的“nome”,因此全局值应为85,任何人都可以知道如何执行此操作?

我的PHP

<?PHP while( have_rows('wallet_rePEater') ): the_row(); 

echo '<div class="promotoras_ITem_wallet">  ';
echo '<div class="PRomnames_wallet">  ';
// VARs

$adicionaDOS = get_sub_field('wallet_promotora');

  foreach($adicionados as $post) :

$nome = simple_fields_values("pname1");
$im = simple_fields_values("ftotop");
$cp=$adicionados ;
$imatop = $im; 
$data=get_sub_field('wallet_data');
$evento=get_sub_field('wallet_evento');
$obs=get_sub_field("wallet_obs");  
$numeros_horas = get_sub_field("Wallet_n_horas");
$valor_horas = get_sub_field("wallet_valorh");
$evento = get_sub_field("wallet_evento");
$horarios = get_sub_field("wallet_horario");

$total_parcial = $valor_horas * $numeros_horas."€";
$ii = wp_get_attachment_image($imatop[0]);


?>

<table id="wallet_table1" width="900px" border="0" cellspacing="2" cellpadding="0">
  <tbody>
    <tr>
       <tr onmouSEOver="this.style.backgroundColor='#ffff66';" onmouSEOut="this.style.backgroundColor='#d4e3e5';">

      <td class="wallet_data_img" width="5"><div class="w_promotora_images"><?PHP echo wp_get_attachment_image($imatop[0]);  ?></td>
      <td class="wallet_data_data" width="20"><?PHP echo the_sub_field('wallet_data'); ?> </td>
      <td class="wallet_data_nome" width="200"><?PHP echo $nome[0];$nomes[]=$nome[0];?></td>
      <td class="wallet_data_evento" width="10"> <?PHP echo the_sub_field("wallet_evento"); ?></td>
      <td class="wallet_data_horarios" width="10"><?PHP echo the_sub_field("wallet_horario");  ?></td>
      <td class="wallet_data_obs" width="10"><?PHP echo the_sub_field("wallet_obs"); ?></td>
      <td class="wallet_data_horas" width="10"><?PHP echo the_sub_field("Wallet_n_horas")."h"; ?></td>
      <td class="wallet_data_valorh" width="5"><?PHP echo the_sub_field("wallet_valorh")."€"; ?></td>
      <td class="wallet_data_props" width="5"><?PHP echo the_sub_field("wallet_props"); ?></td>
      <td class="wallet_data_total" width="5">Parcial: <?PHP echo $total_parcial; ?> global: 

</td> </tr></tbody></table>


<?PHP

解决方法

查询数据填充到关联数组中,然后输出它.
你可以这样做:

$qry = new WP_Query('post_type' => 'your_post_type','posts_per_page' => -1)
$arr = array();
while($qry->have_posts()) {
    $qry->the_post()
    $nam = //Get the name data;
    $val = //Get the «global» data;
    if($qry[$nam]) {
        $qry[$nam]['global'] += $val;
    }
    else {
        $qry[$nam] = array(
            'foto' => //Photo data of the current post,'name' => //Photo data of the current post,//and so on
            'global' => $val,);
    }
}
foreach($qry as $key => $data) {
    //Output your table here
}

脚本宝典总结

以上是脚本宝典为你收集整理的如果单元格重复,php表添加值全部内容,希望文章能够帮你解决如果单元格重复,php表添加值所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。