我試圖填充一個HTML表格與MySQL數據,我有以下數據在MySQL:填充HTML表格和計數行
ID, IP, Referal
我想創建一個表,其中顯示的列表在referals以及多久它們發生,例如:輸出
ID, IP, Referal
1 1.1.1.1 google.com
2 2.2.2.2 google.com
3 3.3.3.3 test.com
4 4.4.4.4 another.com
應該:
google.com 2
test.com 1
another.com 1
我已經試過是這樣的:
<table class="table table-bordered table-primary">
<tbody>
<?php
$sql="SELECT * FROM traffic";
$result=mysql_query($sql);
?>
<?php while($row = mysql_fetch_array($result)) { ?>
<tr >
<td class="tc"><font face="Arial, Helvetica, sans-serif"><?php if($row['referal']==''){
echo "Empty Referal";
} else { echo $row['referal']; }?></font></td>
<td class="tc"><center><font face="Arial, Helvetica, sans-serif"><?php $referal = $row['referal'];
$sql="SELECT COUNT(*) FROM traffic WHERE referal = $referal";
$num_rows = mysql_num_rows($result);
echo "$num_rows";
?></font></center></td>
</tr>
<?php } ?>
</tbody>
</table>
但是,這並不能指望每個單獨參考,這也創造了一個新的錶行的每個條目,即使轉診是一樣的。
任何幫助,非常感謝。
可以打印輸出,你通過使用print_r($ result)從查詢中獲取它; – 2013-03-26 18:00:50