没有做很多php/mysql,但这看起来应该是一个简单的修复,我可能只是搞砸了一些小东西。很抱歉这么长时间的解释想要彻底
我有一个mysql数据库,里面满是健身测试结果,网站上有一个页面,显示登录人员的结果。
我们的设备收集的具体数据称为平衡对称,其结果要么是正数,要么是负数。如果一个人有-15%对称或更少,他们需要额外的工作在他们的左腿,如果他们是+15%对称或更少,他们需要更多的工作,他们的右腿。
这是一个非常重要的因素,所以我试图让他们知道在页面顶部的“红旗”。数据以负数或正数的形式存储在数据库中。
我基本上希望代码可以这样做:
- if the data is >= 15 then it spits out that they need more work on their right leg
- if the data is <= -15 then it spits out that they need more work on their left leg
- if the data is anything else, so between -14 and 14, or if it is null (sometimes they may not have done the balance part of the fitness test due to injury) then nothing is displayed它与下面代码的工作方式是
- if >= 15 works perfectly tells them to work on their right leg
- if <= -15 works perfectly tells them to work on their left leg
- if between -14 and 14 works perfectly tells them nothing
- if null tells them to work on their left leg for some reason. how do I make it so that the null value is handled the same way as the values between -14 and 14<?php
if ($row['field_symmetry_value'] >= 15){
echo " <div class='train_row1'>
<div class='train_row_inside'>
<div class='train_column1rf'><img src='http://racebattlerecover.com/images/redflag.png' /></div>
<div class='train_column3rf'><h3>IMPORTANT: Your balance symmetry between your left and right leg is off by more than 15%. You need to add extra balance exercises to your right leg.</h3></div>
</div>
</div>";
}
elseif ($row['field_symmetry_value'] <= -15){
echo " <div class='train_row1'>
<div class='train_row_inside'>
<div class='train_column1rf'><img src='http://racebattlerecover.com/images/redflag.png' /></div>
<div class='train_column3rf'><h3>IMPORTANT: Your balance symmetry between your left and right leg is off by more than 15%. You need to add extra balance exercises to your left leg.</h3></div>
</div>
</div>";
}
?>谢谢你的帮助!
发布于 2011-10-20 03:37:46
我不知道为什么,但出于某种原因,null被认为不到-15。我认为null在数值比较中会被视为0,但显然不是。您可以很容易地修复这个问题:
else if (!is_null($row['field']) && $row['field'] <= -15) {您还可以在查询中执行以下检查:
COALESCE(field_symmetry_value, 0)如果field_symmetry_value是NULL,它将返回0,它不会打印任何内容。
https://stackoverflow.com/questions/7830449
复制相似问题