【发布时间】:2017-05-23 17:08:49
【问题描述】:
我想删除行中的重复数据。
我的代码如下:
$host = "localhost";
$user = "user";
$password = "pass";
$database = "test4";
$cxn = mysqli_connect($host,$user,$password,$database) or die ("Connection Error");
$query = "SELECT * FROM sample";
$result = mysqli_query($cxn, $query);
$field_row = mysqli_num_rows($result);
$fields_num = mysqli_num_fields($result);
echo "<h1>Table: $database </h1>";
echo " <table border='1' width='50%'><tr> ";
// printing table headers
for ($i=0; $i<$fields_num; $i++){
$field = mysqli_fetch_field($result);
echo "<td><b>{$field->name}</b></td> ";
}
echo "</tr>\n";
// printing table rows
while ($row = mysqli_fetch_row($result)){
echo "<tr>";
// $row is array... foreach(..)put every element
// of $row to $cell variable
foreach ($row as $cell){
echo " <td>$cell</td> ";
}
echo "</tr>\n";
}
- 要删除重复的“date”和“transac”。
希望大家能给我一个更好的解决方案~!
非常感谢~!
【问题讨论】:
-
将
date和transac的值保存在变量中。如果当前行中的值与变量相同,则输出一个空白单元格而不是该行中的值。