我有一张订阅者表。每个订户行具有字段w1,w2,w3,w4,w5。
row1 email | w1 | w2 | w3 | w4 | w5
row2 email | w1 | w2 | w3 | w4 | w5
row3 email | w1 | w2 | w3 | w4 | w5
'w'字段可以有0,1或2
我需要运行查询检查'w'字段,如果该字段有2重新运行查询并检查下一个'w'
示例:
run the function for w1;
if w1 == 2
run the function for w2;
if w2 == 2
run the function for w3;
if w3 == 2
run the function for w4;
if w4 == 0 or == 1
set variable to true
OR if w4 == 2
run the function for w5
这是我目前的职能:
function checkForComplete($nextwidgetNumber, $email) {
global $mysqli, $response;
$complete = false;
$nextwidget = 'w'.$nextwidgetNumber;
if ($stmt = $mysqli->prepare("SELECT ".$nextwidget." FROM subscribe WHERE emailaddr=? AND trash != 1 AND archive != 1")) {
$stmt->bind_param('s', $email);
$stmt->execute();
/* bind result variables */
$stmt->bind_result($widget);
$stmt->store_result();
$stmt->fetch();
// if($stmt->num_rows > 0)
if($widget == '2')
$complete = true;
$response['status'] = "successful completed widget";
$response['complete'] = $complete;
} else {
$response['status'] = "query failed";
}
$stmt->close();
return $response;
}
这是函数调用:
checkForComplete($nextwidgetNumber,$email);
答案 0 :(得分:0)
select @variable = 1
from your_table
where w2 = 2
and w3 = 2
and w4 in (0,1)