PHP问题,高手帮帮忙
if($usertype="teachers"){$sql="SELECTU.user_idASuser_id,U.nomASname,U.prenomASfirstna...
if ($usertype = "teachers") {
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
WHERE U.isPlatformAdmin = 0 AND U.isCourseCreator = 1";
echo $sql;
}
if ($usertype = "admin") {
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
WHERE U.isPlatformAdmin = 1";
echo $sql;
}
就是这段代码。不管接受到的值是 admin 还是 teachers.
它都会执行第一个if . elseif 不执行。 怎么办? 展开
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
WHERE U.isPlatformAdmin = 0 AND U.isCourseCreator = 1";
echo $sql;
}
if ($usertype = "admin") {
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
WHERE U.isPlatformAdmin = 1";
echo $sql;
}
就是这段代码。不管接受到的值是 admin 还是 teachers.
它都会执行第一个if . elseif 不执行。 怎么办? 展开
3个回答
展开全部
if ($usertype == "teachers") {
$_whereStr = "WHERE U.isPlatformAdmin = 0 AND U.isCourseCreator = 1";
} else if ($usertype == "admin") {
$_whereStr = "WHERE U.isPlatformAdmin = 1";
}
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
{$_whereStr}";
echo $sql;
$_whereStr = "WHERE U.isPlatformAdmin = 0 AND U.isCourseCreator = 1";
} else if ($usertype == "admin") {
$_whereStr = "WHERE U.isPlatformAdmin = 1";
}
$sql = "SELECT U.user_id AS user_id,
U.nom AS name,
U.prenom AS firstname,
U.email AS email,
U.officialCode AS officialCode,
U.phoneNumber AS phoneNumber,
U.pictureUri AS pictureUri,
U.creatorId AS creator_id,
U.isCourseCreator,
U.isPlatformAdmin AS isPlatformAdmin
FROM `" . $tbl_mdb_names['user'] . "` AS U
{$_whereStr}";
echo $sql;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$usertype = "admin" 这是赋值,不是判断。应该这样$usertype == "admin"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询