php表在单元格重复时添加值
我有一个wordpress循环检索这样的表: 我想检查名称是否重复,如果重复,则进行部分值之和以显示总数。 在我的屏幕截图上,第一行和第三行有相同的“nome”,所以全局值应该是85,有人能告诉我怎么做吗 我的php:php表在单元格重复时添加值,php,wordpress,loops,Php,Wordpress,Loops,我有一个wordpress循环检索这样的表: 我想检查名称是否重复,如果重复,则进行部分值之和以显示总数。 在我的屏幕截图上,第一行和第三行有相同的“nome”,所以全局值应该是85,有人能告诉我怎么做吗 我的php: <?php while( have_rows('wallet_repeater') ): the_row(); echo '<div class="promotoras_item_wallet"> '; echo '<div class="prom
<?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
}
我的信息是这样的:所以,只需在while循环中获取数据,并将其放在foreach循环$key中正确的位置(注释所在的位置)就是名称,这样您就可以在数组中使用它或复制它,就像$data['name']
对不起,我对循环有点陌生。。。我只是用我的代码编辑我的问题!也许你现在可以帮我编辑你的代码,但没有乐趣。。。我想如果钱包数据名称重复做一个$total\u parcial的总和,并显示在显示为global…(全球)的行上!谢谢你的帮助。真的很感激首先我不知道你在哪里关闭while和foreach循环。其次,$adicionados应该是foreach循环工作的数组。如果$adicionados不是数组,则不需要foreach循环