0

テーブルに正しい出力を持たせることができないようです。コードは次のとおりです。

<div class="bubbleTitle">Spetsialistide tööaeg graafiku alusel</div>
    <table style="width: 600px" class="slicedTable">

        <tr>
        <th>Spetsialist</th>
        <th>Tunnid</th>
    </tr>

<tr>            
    <?php foreach($specs as $specName => $spec): ?>
    <td><?php echo $specName?></td>
            <?php foreach($tunnid as $tund): ?>

    <td><?php echo $tund?></td>
</tr>
     <?php endforeach; ?>
<?php endforeach; ?>

このスレッドですべてを試しました: Nested Loop in table PHP ですが、いずれも機能していません。出力は次のとおりです。

name - 値
value2
value3
name2 - 値
value2
value3

私はそれが欲しい:

name1 - value1
name 2 - value2 など。

どこ $tunnidから来たのですか:

result = mysql_query("SELECT `worker_id`, SUM(TIMESTAMPDIFF(HOUR, `start`, `end`)) as `total` FROM
    `spa_worker_times` WHERE (`start` BETWEEN '".$validated['start']."' AND '".$validated['end']."') AND
    (`end` BETWEEN '".$validated['start']."' AND '".$validated['end']."') GROUP BY `worker_id`") or die(mysql_error()); 


$tunnid = array();
while ($row = mysql_fetch_assoc($result)) {
    $tunnid[] = $row['total'];

仕様の由来:

$data = $this->BookingProcedures->query("SELECT AProcedure.name, BookingGroup.booking_package_id > 0 AS pack_proc," .
                        "SUM(BookingProcedure.price) AS price, Worker.name, COUNT(BookingProcedure.id) AS num" .
                    " FROM spa_booking_procedure_specialists BookingProcedureSpecialist, " .
                        "spa_booking_procedures BookingProcedure, " .
                        "spa_booking_groups BookingGroup, spa_procedures AProcedure, spa_workers Worker" .
                    " WHERE !BookingProcedure.deleted" .
                        " AND DATE(BookingProcedure.start) >= '".$validated['start']."'" .
                        " AND DATE(BookingProcedure.start) <= '".$validated['end']."'" .
                        " AND BookingProcedureSpecialist.booking_procedure_id = BookingProcedure.id" .
                        " AND Worker.id = BookingProcedureSpecialist.specialist_id" .
                        " AND BookingGroup.id = BookingProcedure.group_id" .
                        " AND AProcedure.id = BookingGroup.procedure_id" .
                    " GROUP BY AProcedure.name, BookingGroup.booking_package_id > 0, Worker.name");
4

4 に答える 4

0
<div class="bubbleTitle">Spetsialistide tööaeg graafiku alusel</div>
<table style="width: 600px" class="slicedTable">
     <tr>
      <th>Spetsialist</th>
      <th>Tunnid</th>
     </tr>
     <tr>            
       <?php foreach($specs as $specName => $spec): ?>
        <td><h2><?php echo $specName?></h2>
        <table><tr>
        <?php foreach($tunnid as $tund): ?>
           <td><?php echo $tund?></td>
       <?php endforeach; ?>
       </tr></table></td>
       <?php endforeach; ?>
     </tr>
 </table>

これはこのように出力されます

Name1
value1 | value2 | value3
Name2
value1 | value2 | value3
于 2013-06-14T11:44:38.923 に答える