我似乎无法理解这一点。我究竟做错了什么?我的数据库中有一个表,并且某些行有一个空列,用于"公司"字段。
我试图在下面的html表中获取"用户自己上传的文件。它属于" 1629"
<?php
// Make a MySQL Connection
mysql_connect("localhost", "", "") or die(mysql_error());
//echo "Connected to MySQL<br />";
mysql_select_db("") or die(mysql_error());
//echo "Connected to Database";
$query = "SELECT company, dmy, COUNT(company) FROM AdTracking WHERE DATE(dmy) = CURRENT_DATE GROUP BY company";
$result = mysql_query($query) or die(mysql_error());
echo "<div style='margin-top:100px;'><center><h2>";
echo date('l jS \ F Y');
echo "<br />";
echo "</h2><center></div>";
echo '
<center> <table class="pure-table pure-table-horizontal">
<thead>
<tr>
<th>Company</th>
<th>Total</th>
</tr>
</thead>
<tbody>
';
// Print out result
while($row = mysql_fetch_array($result)){
if ($row['company'] == NULL) {
echo "Users own uploaded files";
};
echo "<tr>";
echo "<td><strong>" . $row['company'] . "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "</tr>";
}
echo '
</tbody>
</table> </center>
';
?>
答案 0 :(得分:1)
您正在td和tr之外打印。
您已保持格式。
试试这个
echo "<tr>";
echo "<td><strong>" .($row['company'] == NULL ? "Users own uploaded files" : $row['company']). "</strong></td>";
echo "<td>" . $row['COUNT(company)'] . "</td>";
echo "</tr>";
答案 1 :(得分:1)
您应该使用mysql_fetch_assoc()
代替mysql_fetch_array()
答案 2 :(得分:0)
\n
使用mysqli或PDO而不是mysql因为&#34; mysql&#34;被删除了。