【发布时间】:2016-04-19 15:14:23
【问题描述】:
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("email-db2",$con);
$query = "SELECT * FROM report";
$run = mysql_query($query);
echo "<table>
<thead>
<tr>
<th>Contact Email</th>
<th>email1</th>
<th>email2</th>
<th>email3</th>
<th>email4</th>
<th>email5</th>
<th>email6</th>
<th>email7</th>
<th>email8</th>
<th>email9</th>
<th>email10</th>
<th>email11</th>
<th>email12</th>
<th>email13</th>
<th>email14</th>
<th>Total</th>
</tr>
</thead>
<tbody>";
while ($row = mysql_fetch_array($run)) {
$COL1 = $row[0];
$COL2 = $row[1];
$COL3 = $row[2];
$COL4 = $row[3];
$COL5 = $row[4];
$COL6 = $row[5];
$COL7 = $row[6];
$COL8 = $row[7];
$COL9 = $row[8];
$COL10 = $row[9];
$COL11 = $row[10];
$COL12 = $row[11];
$COL13 = $row[12];
$COL14 = $row[13];
$COL15 = $row[14];
echo "<tr>";
echo "<td>"; echo $COL1; echo "</td>";
echo "<td>"; echo $COL2; echo "</td>";
echo "<td>"; echo $COL3; echo "</td>";
echo "<td>"; echo $COL4; echo "</td>";
echo "<td>"; echo $COL5; echo "</td>";
echo "<td>"; echo $COL6; echo "</td>";
echo "<td>"; echo $COL7; echo "</td>";
echo "<td>"; echo $COL8; echo "</td>";
echo "<td>"; echo $COL9; echo "</td>";
echo "<td>"; echo $COL10; echo "</td>";
echo "<td>"; echo $COL11; echo "</td>";
echo "<td>"; echo $COL12; echo "</td>";
echo "<td>"; echo $COL13; echo "</td>";
echo "<td>"; echo $COL14; echo "</td>";
echo "<td>"; echo $COL15; echo "</td>";
echo '<td>';
$yesCount = 0;
$noCount = 0;
for ($i=1; $i<= 15; $i += 2){
if (empty($row['email'.$i])) {
$noCount++;
} else {
$yesCount++;
}
}
echo $yesCount;
echo "</td>";
echo "</tr>";
}
echo "</tbody>
</table>";
这是我的代码
在总的最后一列我想要这个
我在奇数列中发现是,它添加了 2
如果在偶数列中找到是,则添加 5
表示 2x2 + 3x5 = 19 , 19 是总输出
这就是我想要的输出。我该怎么做?
【问题讨论】:
标签: php mysql while-loop count html-table