提前感谢那些花时间研究我的问题的人。我从描述承包商活动的表中获取结果。有大量的真/假字段,我只想显示那些是真的。我创建一个field\u name=>field\u类型的数组,并相应地分析我的显示(抱歉,代码片段太大了。)
$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的结尾
奇怪的结果出现在“switch”语句中,其中“case1”。我当前的测试记录有7个yes/no字段,它们的值都设置为1。他们是
准备好的晚餐
清理晚餐的盘子
购买杂货
洗好的和叠好的衣服
水洗床上用品
真空地毯
清扫厨房地板
我应该为每个“field_type=1”得到两个“echo”:(1)我的测试echo和(2)我最终想要显示的内容,但由于某些原因,它们交替显示-见下图。我已经为此奋斗了两天,尝试if/then解析,但是我得到了这种“每秒钟一次”类型的结果。 screenshot of output from query
谢谢你的建议和指导。
1条答案
按热度按时间lztngnrs1#
我已经找到问题并改正了。它和“span…”标签有关。我用一个类替换了内联的“style=…”。我在类中设置颜色,然后用“class:after”部分删除设置。