Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 避免从select语句中显示重复的值_Php_Mysql - Fatal编程技术网

Php 避免从select语句中显示重复的值

Php 避免从select语句中显示重复的值,php,mysql,Php,Mysql,我使用foreach循环来获取结果,但是我得到了不必要的重复结果。下面您将看到,我得到的值显示了两次以上。在查询select语句中,我在表之间进行内部联接。然后我执行一个foreach循环来显示这些结果。结果显示在三个表格中:academy、courses\u by\u academy和person。它们都共享一个外键academy\u id。我不确定这是查询还是foreach循环的格式。如何显示如下所示的信息而不显示任何重复信息 PHP 当前显示: -------------------COU

我使用foreach循环来获取结果,但是我得到了不必要的重复结果。下面您将看到,我得到的值显示了两次以上。在查询select语句中,我在表之间进行内部联接。然后我执行一个
foreach
循环来显示这些结果。结果显示在三个表格中:academy、courses\u by\u academy和person。它们都共享一个外键academy\u id。我不确定这是查询还是foreach循环的格式。如何显示如下所示的信息而不显示任何重复信息

PHP

当前显示:

-------------------COURSES_OFFERED------------------
Course Name: Biology
Start Date: 2013-11-13
End Date: 2013-11-26
---------------------PERSONEL-----------------------
First Name: Person1
Last Name: Last1
Email: test1@gmail.com
This person has the role of an instructor: 1
This person has the role of a contact: 
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Calculus
Start Date: 2013-11-19
End Date: 2013-11-16
---------------------PERSONEL-----------------------
First Name: Person1
Last Name: Last1
Email: test1@gmail.com
This person has the role of an instructor: 1
This person has the role of a contact: 
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Biology
Start Date: 2013-11-13
End Date: 2013-11-26
---------------------PERSONEL-----------------------
First Name: Person2
Last Name: Last2
Email: test2@gmail.com
This person has the role of an instructor: 0
This person has the role of a contact: 1
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Calculus
Start Date: 2013-11-19
End Date: 2013-11-16
---------------------PERSONEL-----------------------
First Name: Person2
Last Name: Last2
Email: test2@gmail.com
This person has the role of an instructor: 0
This person has the role of a contact: 1
Phone: 1234567890
Fax: 1234567890
表值


如果您的意思是防止重复行,可以使用
distinct
短语

select distinct [columns...] 
from ...

请注意,
distinct
防止使用指定的列复制行。

为什么说有重复行?图像中显示的四行都不同。它适用于完全相似的行。在您的示例中,这四行是不同的,并且没有重复。如何显示所需的信息(所需的显示方式)?
-------------------COURSES_OFFERED------------------
Course Name: Biology
Start Date: 2013-11-13
End Date: 2013-11-26
---------------------PERSONEL-----------------------
First Name: Person1
Last Name: Last1
Email: test1@gmail.com
This person has the role of an instructor: 1
This person has the role of a contact: 
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Calculus
Start Date: 2013-11-19
End Date: 2013-11-16
---------------------PERSONEL-----------------------
First Name: Person1
Last Name: Last1
Email: test1@gmail.com
This person has the role of an instructor: 1
This person has the role of a contact: 
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Biology
Start Date: 2013-11-13
End Date: 2013-11-26
---------------------PERSONEL-----------------------
First Name: Person2
Last Name: Last2
Email: test2@gmail.com
This person has the role of an instructor: 0
This person has the role of a contact: 1
Phone: 1234567890
Fax: 1234567890
-------------------COURSES_OFFERED------------------
Course Name: Calculus
Start Date: 2013-11-19
End Date: 2013-11-16
---------------------PERSONEL-----------------------
First Name: Person2
Last Name: Last2
Email: test2@gmail.com
This person has the role of an instructor: 0
This person has the role of a contact: 1
Phone: 1234567890
Fax: 1234567890
select distinct [columns...] 
from ...