我有mysqli
这个crew_status
查询显示PENDING FOR LINEUP
query
的所有数据,但是现在我的data
显示所有database
在query
这是我的<?php
include '../session.php';
require_once 'config.php';
include 'header.php';
$master = 'MASTER';
$chck = 'CHCK';
$second_engineer = '2E';
$second_mate = '2M';
$third_engineer = '3E';
$third_mate = '3M';
$ce = 'CE';
$bsn = 'BSN';
$ab = 'AB';
$olr = 'OLR';
$dcdt = 'DCDT';
$egdt = 'EGDT';
$cook = 'COOK';
$messman = 'MESSMN';
$crew_status = 'PENDING FOR LINEUP';
$query = "SELECT * FROM `crew_info` WHERE `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? OR `crew_rank` = ? AND `crew_status` = ?";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, 'sssssssssssssss', $crew_status, $master, $chck, $second_engineer, $second_mate, $third_engineer, $third_mate, $ce, $bsn, $ab, $olr, $dcdt, $egdt, $cook, $messman);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $id, $first_name, $middle_name, $last_name, $age, $month, $day, $year, $birth_place, $gender, $martial_status, $religion, $nationality, $email_address, $address_1, $address_2, $course, $school_graduated, $remarks, $note, $date_added, $crew_status, $crew_rank, $image_name, $updated_photo, $passport_registration, $passport_expiration);
?>
:
<?php
while(mysqli_stmt_fetch($stmt)) {
echo "<tr>";
echo "<td>".sprintf("%s%s%s", $first_name, $middle_name, $last_name)."</td>";
echo "<td>".sprintf("%s", $crew_rank)."</td>";
echo "<td>".sprintf("%s", $crew_status)."</td>";
echo '</tr>';
}
?>
有人可以说出问题是什么吗?
def prepareResponce(responceData):
"""Prepares a Json responce with status 200"""
response = JsonResponse(responceData)
return response # {"foo": "bar"}
class CustomBasicAuthentication(BasicAuthentication):
userID = None
userType = None
userAccess = None
userName = None
def is_authenticated(self, request, **kwargs):
if 'admin' in request.user.username:
return prepareResponce({'logged in': 'Admin' })
#return True
return prepareResponce({'not allowed for':userName })
def get_identifier(self, request):
return request.user.username
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
resource_name = 'user'
authentication = CustomBasicAuthentication()
allowed_methods = ['get', 'post']
答案 0 :(得分:3)
用or
,(
包裹你的)
,试试这个:
SELECT *
FROM `crew_info`
WHERE (
`crew_rank` = 'MASTER'
OR `crew_rank` = 'CHCK'
OR `crew_rank` = 'MESSMN'
OR `crew_rank` = '2E'
OR `crew_rank` = '2M'
OR `crew_rank` = 'COOK'
OR `crew_rank` = 'OLR'
OR `crew_rank` = 'AB'
OR `crew_rank` = '3E'
OR `crew_rank` = '3M')
AND `crew_status` = 'PENDING FOR LINEUP'
如果没有()
,如果其中一个OR
匹配,则不会计算条件左。
见:
true || false && false = true
(true || false) && false = false
我认为您最好使用IN
代替OR
,例如:
SELECT *
FROM `crew_info`
WHERE
`crew_rank` IN ('MASTER','CHCK','MESSMN','2E','2M','COOK','OLR','AB','3E','3M')
AND `crew_status` = 'PENDING FOR LINEUP'
<强> 编辑: 强>
SELECT *
FROM `crew_info`
WHERE (crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ? OR crew_rank = ?)
AND crew_status = ?
答案 1 :(得分:1)
您的查询中的一些更改:
SELECT * FROM `crew_info` WHERE (`crew_rank` = 'MASTER' OR `crew_rank` = 'CHCK' OR `crew_rank` = 'MESSMN' OR `crew_rank` = '2E' OR `crew_rank` = '2M' OR `crew_rank` = 'COOK' OR `crew_rank` = 'OLR' OR `crew_rank` = 'AB' OR `crew_rank` = '3E' OR `crew_rank` = '3M') AND (`crew_status` = 'PENDING FOR LINEUP')
希望它会对你有所帮助。
答案 2 :(得分:0)
AND和OR是不明确的。目前还不清楚你是否想要这样的东西:
(A AND B) OR C
或
A AND (B OR C)
添加一些括号以清除:
SELECT * FROM `crew_info` WHERE (`crew_rank` = 'MASTER' OR `crew_rank` = 'CHCK' OR `crew_rank` = 'MESSMN' OR `crew_rank` = '2E' OR `crew_rank` = '2M' OR `crew_rank` = 'COOK' OR `crew_rank` = 'OLR' OR `crew_rank` = 'AB' OR `crew_rank` = '3E' OR `crew_rank` = '3M') AND `crew_status` = 'PENDING FOR LINEUP'
答案 3 :(得分:0)
SELECT * FROM crew_info
WHERE crew_rank
不为空且crew_status
='正在等待线路'
我希望这会奏效。