![](/img/trans.png)
[英]PHP - Converting Array to group duplicates together - phpspreadsheet
[英]array group single and duplicates
我有我的數組循環並建立此列: 頁面鏈接 ,
如果用戶重復,我想對它們進行分組,我希望每個行(pid)都具有這個編號,我希望所有具有相同編號的PID都可以分組。
也許與if語句的一些基多我可以將類添加到數組中的重復項和單打! 請幫忙
// $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>";
?>
這為我工作:
if (in_array($currentPID, $checkedPIDs)) {
// build multiples
} else {
// build unikcs
array_push($checkedPIDs, $currentPID); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.