gpt4 book ai didi

mysql - switch 语句内的奇怪结果

转载 作者:行者123 更新时间:2023-11-29 16:34:14 28 4
gpt4 key购买 nike

预先感谢那些花时间查看我的问题的人。我从描述承包商事件的表格中获取结果。有大量的“对/错”字段,我只想显示那些正确的字段。我创建一个 field_name => field_type 数组并相应地解析我的显示。 (对于大的代码片段表示歉意。)

$result = $mysqli->query($visitsSQL);
if ( $result->num_rows == 0 ){ // Visit records don't exist
$_SESSION['message'] = "Cannot find any unpaid visits";
header("location: error.php");
}
else { // unpaid visits exist
$fields= array();
while ($finfo = mysqli_fetch_field($result)){
$fields [$finfo->name]= $finfo->type ; //this array holds field names -> field types
} //finish fetching keys and types
echo "<br>";
echo "<br>Begin visit records<br>";
echo "<div class='review_row'> </div>"; //this puts a thin line to separate visits

while ($visit = $result->fetch_assoc()) { //here's where each visit is compiled and sent to screen

echo "<div class='review_row'>"; //this puts a thin line on the bottom to separate visits

foreach ($fields as $k => $v) {

$field_name = $k;
$field_type = $v;
$field_data = $visit[$field_name];

switch ($field_type) {

case 1: //The field is a True / False field
if ($field_data ==1){ //show the field only if the value is set to True
echo "I am a YES/NO field called " . $field_name . " <br>"; //This line is a test
echo "<span style='color: #009999;> - " . $field_name . "</span><br>";
}
break;
case 4: //The field is a double numeric
if ($field_data != null) { //show the field only if the value is set to True
echo "<span style='color: #b38f00';>" . $field_name . "</span> " . $field_data . "<br>";
}
break;
case 253: //A text field
if ($field_data != null) {
echo "<span style='color: #b38f00';>" . $field_name . "</span> " . $field_data . "<br>";
}
break;
case 254: //a Datetime field
if ($field_data != null) {
echo "<span style='color: #b38f00';>" . $field_name . "</span> " . $field_data . "<br>";
}
break;
default: { //field type is not represented above
// do nothing so far I take care of each field type above
}
} //end of switch
} //end of foreach
} //end of while loop for the query results
echo "</div>";

}//if/else 结束,确定是否有记录要显示

奇怪的结果出现在“case 1”的“switch”语句中。我当前的测试记录有7个YES/NO字段,其值全部设置为1。它们是

  • 准备晚餐
  • 清理晚餐餐具
  • 购买杂货
  • 洗过并折叠的衣服
  • 洗过的床上用品
  • 吸尘地毯
  • 清扫厨房地板

对于每个“field_type = 1”,我应该得到两个“回声”:(1)我的测试回声和(2)我最终想要显示的内容,但由于某种原因它们交替显示 - 请参见下图。我已经为此奋斗了两天,也尝试了 if/then 解析,但我得出了这种“每隔一”类型的结果。

screenshot of output from query

感谢您的任何想法或指导。

最佳答案

我已发现问题并已纠正。它与“span...”标签有关。我用一个类替换了内联“style=...”。我在类中设置了颜色,然后使用“class:after”部分删除了设置。

关于mysql - switch 语句内的奇怪结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53706613/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com