简体   繁体   English

PHP Mysqli从数据库中选择两个DISTINCT

[英]PHP Mysqli select two DISTINCT from data base

I am trying to fetch two different DISTINCT values from data base am not able to do that that gives me an error. 我试图从数据库中获取两个不同的DISTINCT值,但无法做到这一点,这给了我一个错误。 I don't want both to be combined in as statement and fetch as one I need individual DISTINCT values. 我不希望将两者都合并为一个语句并作为我需要单独的DISTINCT值来获取。

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT AttendanceID from attendance_master where Attendence_taken_by !='admi' at line 1\\ 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以便在“ attendence_taken_by!='admi'在第1行的'attendence_taken_by!='admi'附近使用'DISTINCT AttendanceID”

My Query 我的查询

$query = "select DISTINCT Standard , DISTINCT AttendanceID  from attendance_master where  Attendence_taken_by !='$admin'  and  SchoolID='$schoolid' and AttendanceDate >= '$tfrom_date' and AttendanceDate <= '$tto_date' ";

$result = mysqli_query($mysqli,$query)or die(mysqli_error($mysqli));
while($row=mysqli_fetch_array($result))
{
    echo "<table><tr>".$row["Standard"]."</tr><tr>".$row["AttendanceID"]."</tr></table>";
}

Syntax of DISTINCT is DISTINCT语法是

SELECT DISTINCT column_name,column_name
FROM table_name;

So change your query with 所以用

$query = "select DISTINCT Standard , AttendanceID  from attendance_master.....

Instead of assign direct value use bind_param 代替分配直接值,请使用bind_param

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM