Php 如何在excel中导出时不打印重复数据?

Php 如何在excel中导出时不打印重复数据?,php,mysql,Php,Mysql,我需要将数据库中的数据导出到excel,但希望避免重复日期,例如如果有两个相同的条目,则只应打印一个 这就是我得到的 这就是我需要的 在excel中导出 <?php $DB_Server = "localhost"; $DB_Username = "root"; $DB_Password = ''; $DB_DBName = "gst"; $DB_TBLName = "form"; $filename = "data"

我需要将数据库中的数据导出到excel,但希望避免重复日期,例如如果有两个相同的条目,则只应打印一个

这就是我得到的

这就是我需要的

在excel中导出

<?php

$DB_Server = "localhost";   
$DB_Username = "root";  
$DB_Password = '';               
$DB_DBName = "gst";         
$DB_TBLName = "form";    
$filename = "data";         

$sql = "Select * from $DB_TBLName";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());

$Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());   

$result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());    
$file_ending = "xls";

header("Content-Type: application/xls");    
header("Content-Disposition: attachment; filename=$filename.xls");  
header("Pragma: no-cache"); 
header("Expires: 0");

$sep = "\t"; 
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");    

    while($row = mysql_fetch_row($result))
    {
        $schema_insert = "";
        for($j=0; $j<mysql_num_fields($result);$j++)
        {
            if(!isset($row[$j]))
                $schema_insert .= "NULL".$sep;
            elseif ($row[$j] != "")
                $schema_insert .= "$row[$j]".$sep;
            else
                $schema_insert .= "".$sep;
        }
        $schema_insert = str_replace($sep."$", "", $schema_insert);
        $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
        $schema_insert .= "\t";
        print(trim($schema_insert));
        print "\n";
    }   
?>

我会首先通过不从数据库查询重复值来解决这个问题,例如,使用
distinct
关键字:

$sql = "SELECT DISTINCT * FROM $DB_TBLName";
# Here --------^

那么我该如何解决这个问题呢,先生?@PratikPurohit我已经给出了答案-使用
选择distinct
@PratikPurohit没有人能用这么少的信息帮助你。请回答您的问题,并添加一些示例输入数据、您获得的结果以及您尝试获得的该示例结果。完成先生已插入图片以获得帮助,请帮助