数组单个和重复

时间:2015-12-28 12:52:47

标签: php arrays loops

我的数组循环并构建此列: page link

我想对用户进行分组,如果他们重复,我的每一行都有这个号码(pid)我希望所有具有相同号码的PID分组。

也许用if语句的一些kida我可以在数组中添加重复项和单数的类!请帮忙

// $strSQL = "SELECT *, SUM(totalparcial) as Soma FROM bruno_wallet GROUP BY nome "; 
$strSQL = "SELECT * from bruno_wallet GROUP BY id ORDER BY nome ASC "; 

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
// Each row will be made into an array ($row1) using mysql_fetch_array
$sum = 0;
$data = array();
while($row1 = mysql_fetch_array($rs)) {
    $events = array_unique($row1);
    $data[] = $events;

}

//now loop over data instead of mysql_fetch_array
foreach ($data as $events) {
    $currentPID = $events[12];

    echo "<div  id='linha_$events[0]' class='cor promotora_$events[12] cf'>";    

    echo "<div class='tb1'>{$events[0]}</div>";  //id
    echo "<div class='tb1'>{$events[7]}</div>";  //foto
    echo "<div class='tb1'>{$events[3]}</div>";  //data
    echo "<div class='tb1'>{$events[2]}</div>";      //nome
    echo "<div class='tb1'>{$events[12]}</div>";  
    echo "<div class='tb1'>{$events[4]}</div>";  //evento
    echo "<div class='tb1'>{$events[5]}</div>";  //horario
    echo "<div class='tb1'>{$events[6]}</div>";  //obs
    echo "<div class='tb1'>{$events[10]}h</div>"; //horas
    echo "<div class='tb1'>{$events[9]}€</div>";  //valor hora
    echo "<div class='tb1'>{$events[1]}</div>";  //Props
    echo "<div class='tb1'>{$events[8]}</div>"; //tparcial 

    echo "</div>";

    ?>

1 个答案:

答案 0 :(得分:0)

这对我有用:

     if (in_array($currentPID, $checkedPIDs)) {
   // build multiples

        } else { 


   //     build unikcs 
        array_push($checkedPIDs, $currentPID);  ?>