我列出了在users表中注册的用户。但我想在名称栏中隐藏名称“SuperAdmin”。
我的查询就像这样
$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.job, u.signature, u.office_phone, u.office_fax, u.user_mobile,";
$sql.= " u.admin, u.login, u.webcal_login, u.phenix_login, u.phenix_pass, u.note,";
$sql.= " u.pass, u.pass_crypted, u.pass_temp,";
$sql.= " u.fk_societe, u.fk_socpeople, u.fk_member, u.ldap_sid,";
$sql.= " u.statut, u.lang, u.entity,";
$sql.= " u.datec as datec,";
$sql.= " u.tms as datem,";
$sql.= " u.datelastlogin as datel,";
$sql.= " u.datepreviouslogin as datep,";
$sql.= " u.photo as photo,";
$sql.= " u.openid as openid,";
$sql.= " u.ref_int, u.ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))
{
$sql.= " WHERE u.entity IS NOT NULL";
}
else
{
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
}
if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba
{
$sql.= " AND (u.ldap_sid = '".$sid."' OR u.login = '".$this->db->escape($login)."') LIMIT 1";
}
else if ($login)
{
$sql.= " AND u.login = '".$this->db->escape($login)."'";
}
else
{
$sql.= " AND u.rowid = ".$id;
}
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$obj = $this->db->fetch_object($result);
if ($obj)
{
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->ref_int = $obj->ref_int;
$this->ref_ext = $obj->ref_ext;
$this->ldap_sid = $obj->ldap_sid;
$this->nom = $obj->name; // TODO deprecated
$this->lastname = $obj->name;
$this->prenom = $obj->firstname; // TODO deprecated
$this->firstname = $obj->firstname;
$this->login = $obj->login;
$this->pass_indatabase = $obj->pass;
$this->pass_indatabase_crypted = $obj->pass_crypted;
$this->pass = $obj->pass;
$this->pass_temp = $obj->pass_temp;
$this->office_phone = $obj->office_phone;
$this->office_fax = $obj->office_fax;
$this->user_mobile = $obj->user_mobile;
$this->email = $obj->email;
$this->job = $obj->job;
$this->signature = $obj->signature;
$this->admin = $obj->admin;
$this->note = $obj->note;
$this->statut = $obj->statut;
$this->photo = $obj->photo;
$this->openid = $obj->openid;
$this->lang = $obj->lang;
$this->entity = $obj->entity;
$this->datec = $this->db->jdate($obj->datec);
$this->datem = $this->db->jdate($obj->datem);
$this->datelastlogin = $this->db->jdate($obj->datel);
$this->datepreviouslogin = $this->db->jdate($obj->datep);
$this->webcal_login = $obj->webcal_login;
$this->phenix_login = $obj->phenix_login;
$this->phenix_pass_crypted = $obj->phenix_pass;
$this->societe_id = $obj->fk_societe;
$this->contact_id = $obj->fk_socpeople;
$this->fk_member = $obj->fk_member;
if (! $this->lang) $this->lang='fr_FR';
$this->db->free($result);
是否可以使用UNION方法,有人帮助我。我尝试添加Where Distinct但它不起作用。我只想隐藏名称SuperAdmin
答案 0 :(得分:2)
在FROM行
之后添加$sql.= " WHERE u.name != 'SuperAdmin'";
答案 1 :(得分:2)
一个WHERE
条件会:
$sql .= " WHERE `u`.`name` <> 'SuperAdmin';";
这将获取除name = 'SuperAdmin';
答案 2 :(得分:0)
您可以在查询结尾添加WHERE条件,例如
$ sql。=“WHERE u.name NOT LIKE'SuperAdmin'”;