doudi8298 2014-10-17 02:05
浏览 66
已采纳

在mysql php if语句中使用负数?

I have the following code with an if statement and the value is negative one is some rows of data. Yet when I use this statement it reads the -1 value as 1.

if ($row ['bedrooms'] == '-1')
{
    echo "<td class='propdescres'>Studio</td></tr>";
}
else
{
    echo "<td class='propdescres'>" . $row['bedrooms'] . "</td></tr>";
}

I tried adding

$studio = $row ['bedrooms']*'-99';

And changing my statement to:

if ($studio == '99')
{
    echo "<td class='propdescres'>Studio</td></tr>";
}
else
{
    echo "<td class='propdescres'>" . $row['bedrooms'] . "</td></tr>";

The following is the query I am using to get the data:

$result = mysqli_query($con, "SELECT realty.id, realty.unit_num, realty.address, realty.price, realty.bedrooms, realty.bathrooms, realty.metadesc FROM realty

The field type is tinyint(3) and when I query the database for bedrooms = -1 it returns vales but in my echo results in php all the -1 values are 1.

Can somebody please give me a little insight as to what I am doing wrong or how I can retrieve negative values?

Thank you.

  • 写回答

2条回答 默认 最新

  • doudiejian5827 2014-10-17 03:37
    关注

    Try to use so:

    $someNegVal = '-1';
    if (isset($row['bedrooms']) &&  $row['bedrooms'] == -1*abs($someNegVal)) {
    //....
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分