我使用树状视图,我想对数据进行计数并显示在子项上,但是该父项可以显示子项的总和,依此类推
我有2张桌子:
table_estruc has (id - text - parent_id)
table_resp has (field_id, field_name, id, parent_id)
我可以算出table_resp
上table_estuc.id = table_resp.id
上的所有记录,甚至算作要显示在父ID中,但我无法实现的是计数侦查并将其显示在父ID上当前的parent_id
等。
$sql = "SELECT * FROM `estructura_set`";
$res = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));?>
<?php $a = $row["area"];
$cct = $row["cct"];
$mid = $row["id"];
$mparenid = $row["parent_id"];
$promovidos_tot_query2 = "SELECT COUNT tbl_promotor_parent_id, (promov.tbl_promovido_ID) as promo2 FROM tbl_promovidos promov INNER JOIN tbl_promotores pmt ON pmt.tbl_promotor_ID = promov.tbl_promovido_promotor_ID
WHERE pmt.tbl_promotor_eid= '$mid'";
$res2 = mysqli_query($conn, $promovidos_tot_query2) or die("database error:". mysqli_error($conn));
$total_promov2 = $res2->fetch_assoc();
$promovidos2 = $total_promov2['promo2'];
$promovidosp = $total_promov2['tbl_promotor_parent_id'];
$promo = $promovidos2;
$sualternos = $promovidos3;
$grantotal = $promo + $sualternos;
$promo = $promovidos2;
$sualternos = $promovidos3;
$grantotal = $promo + $sualternos;
$row["text"] = $row["text"].' - ('.$row["cct"].') <span class="badge badge-primary"> Promovidos <span class="badge badge-light">'. $promo.'</span></span>
<span class="badge badge-primary"> Subalternos <span class="badge badge-light">'. $sualternos .'</span></span>
<span class="badge badge-primary"> Total <span class="badge badge-light">'. $grantotal .'</span></span>';
$data[] = $row;
}