0
我正在用php生成一个程式化的表格,但由于某些原因,它会创建我的Date和Count的重复列。有人可以帮助弄清楚为什么这发生在我身上?谢谢显示mysql数据时重复列
<?php
include("dbconnect.php");
$link=Connection();
$result = mysql_query(
"SELECT Date, Count
FROM testLocation
WHERE Date
BETWEEN '2016-04-10 00:01:11' AND '2016-04-23 00:01:11'"
,$link
);
if($result!==FALSE){
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo '<tr><th>Date</th><th>Count</th></tr>';
while($row = mysql_fetch_array($result)) {
echo '<tr>';
foreach($row as $key=>$value1){
echo '<td>', $value1,'</td>';
}
echo '<tr>';
}
echo '</table><br />';
mysql_free_result($result);
mysql_close();
}
?>
尝试在你的SQL中使用'DISTINCT'。 – Blank
嗨里诺,我不幸已经尝试过,它没有工作。 – amiao
from docs - ['mysql_fetch_array()'](http://php.net/manual/en/function.mysql-fetch-array.php) - * - 将结果行作为关联数组,数组, 或两者*。默认值都是(即'MYSQL_BOTH'),所以你得到了关联数组和数组数组。 ($ row = mysql_fetch_array($ result,MYSQL_ASSOC)){'** OR **'while($ row = mysql_fetch_array($ result)){'to' ){' – Sean