这是我的查询,
$query=mysql_query("select *
from quiz_grades as grade,
user_info_data as info,
user as user
where user.id=grade.userid
and user.id=info.userid
and grade.quiz=12
and info.fieldid=1
and info.data='AP'
order by data ASC, grade DESC");
从下表中
$USER->id
是当前登录的用户变量。
如果userid
= $USER->id
属于AP,则应显示所有AP。
如果userid
= $USER->id
属于TL,则应显示所有TL。
info.data
存储AP和TL记录。
<table>
<tr>
<th>userid</th>
<th>data</th>
</tr>
<tr>
<td>1</td>
<td>AP</td>
</tr>
<tr>
<td>2</td>
<td>TL</td>
</tr>
<tr>
<td>3</td>
<td>AP</td>
</tr>
<tr>
<td>4</td>
<td>AP</td>
</tr>
<tr>
<td>5</td>
<td>TL</td>
</tr>
<tr>
<td>6</td>
<td>TL</td>
</tr>
<tr>
<td>7</td>
<td>AP</td>
</tr>
<tr>
<td>8</td>
<td>TL</td>
</tr>
<tr>
<td>9</td>
<td>TL</td>
</tr>
<tr>
<td>10</td>
<td>TL</td>
</tr>
</table>
先谢谢
答案 0 :(得分:0)
考虑到user
表中有一个位置字段
select grade.* from quiz_grades as grade
join user as user on user.id=grade.userid and grade.quiz=12
join user_info_data as info on user.id=info.userid
where `fieldid`=1
and info.data = 'telengana'
order by data ASC, grade DESC
答案 1 :(得分:0)
假设您有一个要使用的位置字段(locationField
):
$query=mysql_query("
SELECT *
FROM quiz_grades AS grade,
user_info_data AS info,
USER AS USER
WHERE USER.id = grade.userid
AND USER.id = info.userid
AND grade.quiz = 12
AND ` fieldid `= 1
AND `location` IN (SELECT location FROM user_info_data WHERE user_info_data.userid = {$USER->id})
ORDER BY data ASC,
grade DESC ");