【问题标题】:How To Make Json_encode PHP To An Text String Number如何将 Json_encode PHP 转换为文本字符串数字
【发布时间】:2021-02-27 19:43:28
【问题描述】:

大家好,我想问一下如何使用 Json_Encode 对文本进行输出 这是我的代码

型号

function count_topup($ID)
{
    $this->db->select_sum("Jumlah");
    $this->db->from('topup');
    $this->db->where('id_user',$ID);
    $query= $this->db->get();
    return $query->result_array();
}

控制器

  $data['Count'] = $this->user_model->count_topup($ID);

查看

<?php echo json_encode($Count);?>

它会给出输出 [{"Jumlah":"150000"}]

如何只显示150000?感谢您的帮助

【问题讨论】:

  • 现在试试我的更新视图。

标签: php json codeigniter-4


【解决方案1】:

不需要json_encode();

控制器:-

$data['Count'] = $this->user_model->count_topup($ID);
$this->load->view('Your_view', $data);

查看:-

   foreach ($Count as $c)
 {
   <?php echo $c['Jumlah'];?>
  }

注意:-关于数组数据如何从控制器传递到视图是

https://codeigniter.com/userguide3/general/views.html

【讨论】:

  • 我已经在使用这个并给出错误`数组到字符串的转换`
猜你喜欢
  • 1970-01-01
  • 2014-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-16
  • 1970-01-01
相关资源
最近更新 更多