douzhizao0270 2013-06-29 17:28
浏览 15

PDO中数据类型的条件浮动时如何返回结果?

I have a data like this and I call it table normal:

    z       0         0.01       0.02  
   ---    ------     -------    ------

   -3.4   0.0003     0.0003     0.0003

   -3.3   0.0005     0.0005     0.0005

   -3.2   0.0007     `0.0007`     0.0006

   -3.1   0.001      0.0009     0.0009

   -3     0.0013     0.0013     0.0013

And I have value of z = -3.21

it means value of z in rows = -3.2 and in column = 0.01

So, I will get the value = 0.0007

I use PDO in my code to get any value from database:

public function SelectTableZ($col, $z){
        try{
            $query = "SELECT :col as value FROM table_normal WHERE z=:z";

            $this->Statement = $this->Connection->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));

            $this->Statement->bindParam(":col",$col,PDO::PARAM_STR);

            $this->Statement->bindParam(":z",$z,PDO::PARAM_STR);

            $this->Statement->execute();

            $this->Statement->setFetchMode(PDO::FETCH_OBJ);

            $result = $this->Statement->fetchAll();

            $this->Statement->closeCursor();

            if($result){
                return $result;
            } /*else throw new Exception("Comment not selected!");*/ else return false;
        }catch(Exception $e){
            echo "Caught Exception: ".$e->getMessage();
            return null;
        }
    }

and this is the value I want to get from database:

$value = -3.21;

$Z = number_format($value * 10, 0, '', '') / 10;

$col = substr(floor($value * 100), -1);
if ($col > 0) { 
    $col /= 100; 
}

$SelectTableZ = $session->SelectTableZ($col, $z);
if(!empty($SelectTableZ)){
  foreach($SelectTableZ as $data){
    echo $data->value;
  }
}

Is there any solutions to this problem?

thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 r语言神经网络自变量重要性分析
    • ¥15 基于双目测规则物体尺寸
    • ¥15 wegame打不开英雄联盟
    • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
    • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
    • ¥30 eclipse开启服务后,网页无法打开
    • ¥30 雷达辐射源信号参考模型
    • ¥15 html+css+js如何实现这样子的效果?
    • ¥15 STM32单片机自主设计
    • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢