表无法正确回显

时间:2015-07-25 07:35:10

标签: php

我有一张桌子可以让员工缺席,但工作得很好,但是当我尝试在表格的末尾添加一行时,得到每列的总和。一切都错了。我做错了什么?

代码:

<table>
            <tr> 
                <th>Month</th><th>Nbr Of Weekly Vacations</th><th>Nbr Of Yearly Vacations</th><th>Nbr Of Sick Days</th><th>Holidays</th><th>Marriage Leave</th><th>Motherhood Vacation</th><th>Absense With Reason</th><th>Absense Without Reason</th><th>Annual Leave Remaining</th><th>Deducted Yearly Vacation</th><th>Leave Remaining After Deduct</th>
            </tr>';
             $WeeklyVacationCount = 0;
             $YearlyVacationCount = 0;
             $SickDayCount = 0;
             $HolidayCount = 0;
             $MarriageLeaveCount = 0;
             $MotherhoodVacationCount = 0;
             $AbsenceWithReasonCount = 0;
             $AbsenceWithoutReasonCount = 0;

            for($i=1;$i<=12;$i++){
                echo '<tr>
                    <th style="text-align:left;">'.date('F', mktime(0, 0, 0, $i, 10)).'</th>
                    <td>'.getCount($afnbr,$year,$i,'WeeklyVacation').'</td>
                    $WeeklyVacationCount+=$WeeklyVacation;
                    echo "<td>{$WeeklyVacation}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'YearlyVacation').'</td>
                    $YearlyVacationCount+=$YearlyVacation;
                    echo "<td>{$YearlyVacation}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'SickDay').'</td>
                    $SickDayCount+=$SickDay;
                    echo "<td>{$SickDay}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'Holiday').'</td>
                    $HolidayCount+=$Holiday;
                    echo "<td>{$Holiday}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'MarriageLeave').'</td>
                    $MarriageLeaveCount+=$MarriageLeave;
                    echo "<td>{$MarriageLeave}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'MotherhoodVacation').'</td>
                    $MotherhoodVacationCount+=$MotherhoodVacation;
                    echo "<td>{$MotherhoodVacation}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'AbsenceWithReason').'</td>
                    $AbsenceWithReasonCount+=$AbsenceWithReason;
                    echo "<td>{$AbsenceWithReason}</td>"; 
                    <td>'.getCount($afnbr,$year,$i,'AbsenceWithoutReason').'</td>
                    $AbsenceWithoutReasonCount+=$AbsenceWithoutReason;
                    echo "<td>{$AbsenceWithoutReason}</td>"; 
                    <td>'.(15 - getCount($afnbr,$year,$i,'YearlyVacation')).'</td>
                    <td>'.getCount($afnbr,$year,$i,'DeductedVacation').'</td>
                    <td>'.(15 - getCount($afnbr,$year,$i,'YearlyVacation') - getCount($afnbr,$year,$i,'DeductedVacation')).'</td>


                </tr>
                ';
            }
echo "<tr>";
echo "<td>$WeeklyVacationCount</td>";
echo "</tr>";

echo       '</table>

它的回声方式: enter image description here

3 个答案:

答案 0 :(得分:0)

这是因为您没有使用连接运算符来表示变量值。

您的密码:

echo "<td>$WeeklyVacationCount</td>";

代码应该是:

echo "<td>".$WeeklyVacationCount."</td>";

答案 1 :(得分:0)

将循环更改为此

for($i=1;$i<=12;$i++){
            echo '<tr>
                <th style="text-align:left;">'.date('F', mktime(0, 0, 0, $i, 10)).'</th>
                <td>'.getCount($afnbr,$year,$i,'WeeklyVacation').'</td>';
                $WeeklyVacationCount+=$WeeklyVacation;
                echo "<td>{$WeeklyVacation}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'YearlyVacation').'</td>';
                $YearlyVacationCount+=$YearlyVacation;
                echo "<td>{$YearlyVacation}</td>";
                echo '<td>'.getCount($afnbr,$year,$i,'SickDay').'</td>';
                $SickDayCount+=$SickDay;
                echo "<td>{$SickDay}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'Holiday').'</td>';
                $HolidayCount+=$Holiday;
                echo "<td>{$Holiday}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'MarriageLeave').'</td>';
                $MarriageLeaveCount+=$MarriageLeave;
                echo "<td>{$MarriageLeave}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'MotherhoodVacation').'</td>';
                $MotherhoodVacationCount+=$MotherhoodVacation;
                echo "<td>{$MotherhoodVacation}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'AbsenceWithReason').'</td>';
                $AbsenceWithReasonCount+=$AbsenceWithReason;
                echo "<td>{$AbsenceWithReason}</td>"; 
                echo '<td>'.getCount($afnbr,$year,$i,'AbsenceWithoutReason').'</td>';
                $AbsenceWithoutReasonCount+=$AbsenceWithoutReason;
                echo "<td>{$AbsenceWithoutReason}</td>"; 
                echo '<td>'.(15 - getCount($afnbr,$year,$i,'YearlyVacation')).'</td>';
                echo '<td>'.getCount($afnbr,$year,$i,'DeductedVacation').'</td>';
                echo '<td>'.(15 - getCount($afnbr,$year,$i,'YearlyVacation') - getCount($afnbr,$year,$i,'DeductedVacation')).'</td>';


            echo '</tr>';
        }

答案 2 :(得分:0)

您的代码充满了错误。

 echo '<tr>
      <th style="text-align:left;">'.date('F', mktime(0, 0, 0, $i, 10)).'</th>
      <td>'.getCount($afnbr,$year,$i,'WeeklyVacation').'</td>
       $WeeklyVacationCount+=$WeeklyVacation;
        echo "<td>{$WeeklyVacation}</td>"; 

这真是一团糟

 <tr>
     <th style="text-align:left;" >
              <?php echo date('F', mktime(0, 0, 0, $i, 10)); ?>
     </th>
     <td>
              <?php echo getCount($afnbr,$year,$i,'WeeklyVacation'); ?>
     </td>
              <?php $WeeklyVacationCount += $WeeklyVacation; ?>
     <td>
              <?php echo $WeeklyVacation; ?>
     </td>
</tr>