任何人都可以帮我弄清楚我的问题是什么吗?
我在显示数据库中的一些结果时遇到问题。
我试图通过查找查找表来显示用户的所有设置,但结果是跳过其他所有变量。
例如显示(错误):
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语句有关吗?