继续在我的报告中获得重复的结果

时间:2014-02-04 21:01:29

标签: sql duplicates repeat

I have this Query, I need it to pull a report of the registrants, but the report i get keeps duplicating the registrants on the result. 

SELECT DISTINCT * FROM registrants WHERE (paid='Y' AND course_id = '$course_info[0]' AND course_date = '$course_info[1]')

Can anyone tell me what is doing that?

以下是代码的其余部分! 我们希望获得已付款的注册人的结果。但是当你生成报告时,它给了我们相同的信息;让我们说8个注册人一次,然后是两次,然后是三次,依此类推,直到每个注册人至少显示8次为止

$course_report = $_POST['course_report'];

$course_info = explode('~',$course_report);
$course_info[0]; // course_id
$course_info[1]; // course_date

$select = "SELECT DISTINCT * FROM registrants WHERE (paid='Y' AND course_id = '$course_info[0]' AND course_date = '$course_info[1]')";  

$result = mysql_query($select);
while($row = mysql_fetch_assoc($result))
{
$course = $row['course'];
$coursedate = $row['course_date'];

$export = mysql_query($select);
$fields = mysql_num_fields($export); 
// Get header
for ($i = 0; $i < $fields; $i++) {
    $header .= mysql_field_name($export, $i) . "\t";
} 

// Get rows
while($row = mysql_fetch_row($export)) {
    $line = '';
    foreach($row as $value) {                                            
        if ((!isset($value)) OR ($value == "")) {
            $value = "\t";
        } else {
            $value = str_replace('"', '""', $value);
            $value = '"' . $value . '"' . "\t";
        }
        $line .= $value;
    }
    $data .= trim($line)."\n";
}

1 个答案:

答案 0 :(得分:2)

即使您只对三个列进行过滤,也会从表中选择所有列。您的某个列可能会为每个注册人提供不同的数据。你想要分明什么?如果您只想要这三列,那么SELECT DISTINCT PAID, COURSE_ID, COURSE_DATE代替所有列。