PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] Undefined variable 'data' after input some query to variable

 March 05, 2022     codeigniter, php     No comments   

Issue

I'm sorry I have a question, I want to get data from query and send it to view.. Here's my code..

$this->load->model('expert_model');
$data = $this->expert_model->get_result($consultation_id);

$datas = $this->db->select('*')->limit(1)->order_by('CF_Combine', 'DESC')->get_where('hasil', ['id_konsultasi' => $consultation_id])->row();
        
$this->load->view('User/value', $datas);

I have tried dump the $datas and the result is all I want. But, How can I get data from $datas to the User/value's view ? I tried to use $datas but it said undefined 'datas'

I'm sorry I really bad both in english and code :(

And here's my code in view, just want to see it works or not

<?php foreach ($datas as $key) : ?>
<?php echo number_format(($key->CF_Combine * 100), 2) . " %" ?>                   
<?php endforeach ?>

Solution

$this->load->model('expert_model');
$datas=array();  //define $datas is array
$data = $this->expert_model->get_result($consultation_id);

$datas['datas'] = $this->db->select('*')->limit(1)->order_by('CF_Combine', 'DESC')->get_where('hasil', ['id_konsultasi' => $consultation_id])->row();
        
$this->load->view('User/value', $datas);


Answered By - Ganpat Thakor
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing