php table add values if cell repeats

I-am Sam

I have a wordpress loop retriving a table like this:

enter image description here

I want to check if the name repeats it self and if so do a sum of partial values to show the total. On my screenshot the 1st and 3rd rows have the same "nome" so the global value should be 85, can any one tellme how to do this ?

my 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
Codeartist

Stuff the query data into an associative array and after that output it. You can do it like that:

$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
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UICollectionView repeats cell

From Dev

php count and add each values from MySQL table row

From Dev

Add multipage caption by looping from cell values

From Dev

Cannot add values to table using mysql and php

From Dev

How to add a rich Textbox (HTML) to a table cell?

From Dev

Add multiple MySQL results to one cell in a HTML table using PHP

From Dev

Dynamically add colspans and/or rowspans to a table cell

From Dev

php function outside table cell

From Dev

Add view to a cell in a Table View Programmatically

From Dev

Swift - add gesture recognizer to object in table cell

From Dev

Reset values of all UITextfield in custom table cell

From Dev

UICollectionView repeats cell

From Dev

Auto add empty table cell

From Dev

Excel table find and copy cell values

From Dev

jQuery add dynamically cell to a static cell into table

From Dev

Add Cell in the Table View Controller

From Dev

UITableView Repeats First Cell On Occasion

From Dev

Matching multiple cell values on a table

From Dev

Pentaho CDE Table component format cell values

From Dev

PHP changing individual table cell values

From Dev

Add onclick event on a php-generated table cell

From Dev

Array values not showing up in custom table cell

From Dev

table cell Width % values changing other cell width values by itself?

From Dev

Table in C# with conditional cell values

From Dev

join table cell values and reformat by javascript

From Dev

Get Table Cell values and pass to Javascript

From Dev

Extracting values from a cell in a table using BeautifulSoup

From Dev

Add values in a cell R

From Dev

Add overflow table cell in a cell with a header

Related Related

HotTag

Archive