Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多次运行MySql查询,直到在5个字段之一中找到特定值_Php_Mysql_Loops - Fatal编程技术网

Php 多次运行MySql查询,直到在5个字段之一中找到特定值

Php 多次运行MySql查询,直到在5个字段之一中找到特定值,php,mysql,loops,Php,Mysql,Loops,我有一张订户表。每个订户行都有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 r

我有一张订户表。每个订户行都有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);

你试过什么吗?如果是这样,请按问题标签下方的“编辑”按钮将其包含在问题中,记住要包含由您的尝试产生的任何错误。我已添加该功能。我需要调用该函数,如果结果等于2,则将“w”字段增加1,然后再次运行该函数。继续此操作,直到值等于1或0,或者如果所有字段的值都为2,则停止。您尝试过什么吗?如果是这样,请按问题标签下方的“编辑”按钮将其包含在问题中,记住要包含由您的尝试产生的任何错误。我已添加该功能。我需要调用该函数,如果结果等于2,则将“w”字段增加1,然后再次运行该函数。继续此操作,直到值等于1或0,或者如果所有字段的值均为2,则停止此操作
select @variable = 1
from your_table
where w2 = 2
and w3 = 2
and w4 in (0,1)