doushen9863 2017-12-05 18:35
浏览 24
已采纳

SQL-PHP错误解决方案

Evening community,

I stuck at one problem, which I can't find solution for. I would appreciate if you could give me a piece of your advice. In brief, I wrote the following function in a php-file:

public function getCurrencyReal(){

    $sql = "SELECT currency_real FROM currency WHERE currency_id = '4' limit 1";

    $query = $this->db->query($sql);

    $currency_real = $query;

    return $currency_real->row;
}

After that I added the following code in another php file, that should generate XML-list:

$currency_real = $model_module_xmlcreator -> getCurrencyReal();

and

$out .= "<test>" . $currency_real . "</test>";

As a result I've received the following thing:

enter image description here

, saying "Array".

I've realized that I'm asking for an array even though I want to get info only from one field and I actually need a string. So I changed the code a bit to

$currency_real = json_encode($query);

return $currency_real; 

and my next output was enter image description here

I believe that I miss something simple, but I can't find what (the output should be just "33.00"). Pardon me if the question is silly, I've started studying PHP not much time ago.

All best

  • 写回答

1条回答 默认 最新

  • duanhe0817825 2017-12-05 18:42
    关注

    just change this line

    $out .= "<test>" . $currency_real->rows[0]->currency_real . "</test>";

    or

    $out .= "<test>" . $currency_real->row->currency_real . "</test>";

    and don't use json_encode

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器