0

谁能帮我弄清楚我的问题是什么?
我在显示我的数据库中的一些结果时遇到问题。我试图通过在查找表上查找来显示用户的所有设置,但结果正在跳过所有其他变量。

例如它显示(错误):

relationship_status : In a relationship<br>
eye_color : green<br>
religion : christian (catholic)<br>
body_type : average<br>
education : don't say<br>
looking_for : don't say<br>
drinker : don't say<br>

它应该显示(正确):

orientation : straight<br>
relationship_status : In a relationship<br>
hair_color : black<br>
eye_color : green<br>
ethnicity : black<br>
religion : christian (catholic)<br>
politics : liberal<br>
body_type : average<br>
children : don't say<br>
education : don't say<br>
income : don't say<br>
looking_for : don't say<br>
smoker : don't say<br>
drinker : don't say<br>

我检查了$lookup_table_names数组中的变量,它们都是正确的。我的 mysql 语法是正确的,我不知道它为什么会跳过结果。

$lookup_table_names = array('orientation'=>$orientation,'relationship_status'=> $status,'hair_color'=>$hair_color,
                            'eye_color'=>$eye_color,'ethnicity'=>$ethnicity,'religion'=>$religion,
                            'politics'=>$politics,'body_type'=>$body_type,'children'=>$children,'education'=>$education,
                            'income'=>$income,'looking_for'=>$looking_for,'smoker'=>$smoker,'drinker'=>$drinker
);

foreach ($lookup_table_names as $tablename => $val) {
    $query = "SELECT value FROM lookup_".$tablename." WHERE id = ? LIMIT 1";

    if($stmt = $mysqli -> prepare($query)){
        $stmt -> bind_param('i',$val);
        $stmt -> execute();
        $stmt -> bind_result($myvalue);
        $stmt -> fetch();
        echo '<br><br>'.$tablename.' : '.$myvalue.'<br><br>';
    }else{
        printf($stmt->error);
    }
}

这就是我得到的。
如果我不得不猜测,我会说这与 MySQL 语句执行得太快有关? 在此处输入图像描述

4

0 回答 0