Welcome Guest, Not a member yet? Register   Sign In
Why does this query collect only the first letter?
#1

[eluser]shinokada[/eluser]
I have the following db.

Code:
CREATE TABLE IF NOT EXISTS `support_details` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `customer_id` int(10) NOT NULL,
  `date` date NOT NULL,
  `time` int(10) NOT NULL,
  `point_credit` int(10) NOT NULL,
  `note` text NOT NULL,
  `by` varchar(40) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `support_details`
--

INSERT INTO `support_details` (`id`, `customer_id`, `date`, `time`, `point_credit`, `note`, `by`) VALUES
(1, 7, '2010-07-07', 0, 180, 'first credit', 'shin'),
(2, 7, '2010-07-10', 40, 0, 'menu correction.', 'shin'),
(3, 7, '2010-07-09', 30, 0, 'link correction', 'shin');

When I use the following controller and model I get the only first letters.

Controller
Code:
function customer(){
        $data['title'] = "Customer Record";
        $id = $this->uri->segment(4);
        $data['customer_records'] = $this->MSupport->getAllCustomerRecord($id);
        $data['header'] = $this->lang->line('customer_history');
        // This how Bep load views
        $data['page'] = $this->config->item('backendpro_template_admin') . "admin_customer_home";
        $data['module'] = 'support';
        $this->load->view($this->_container,$data);
        
    }

Model
Code:
function getAllCustomerRecord($id){
         $data = array();
        
      //  $Q = $this->fetch('support_details',NULL,NULL,array('customer_id'=>$id));
        $Q = $this->db->select('*')->from('support_details')->where('customer_id', $id);
        $Q = $this->db->get();
         if ($Q->num_rows() > 0){
              $data = $Q->row_array();
        }
        $Q->free_result();    
        return $data;  
        
     }


Outputs

Code:
17201fs

I am trying to get an array of data, with id 1,2,3 and other details.

What am I doing wrong here?

I am hoping someone point out my mistake and lead to the right direction.

Thanks in advance.
#2

[eluser]treeface[/eluser]
Can you do die(var_dump($Q)) before you free the result and post the output here?
#3

[eluser]shinokada[/eluser]
I changed to this and it works now.

Thanks.

Code:
$data = array();
        $this->db->where('customer_id', $id);
        $Q = $this->db->get('support_details');
        if ($Q->num_rows() > 0){
               foreach ($Q->result_array() as $row){
            $data[] = $row;
          }
        }
        $Q->free_result();    
        return $data;




Theme © iAndrew 2016 - Forum software by © MyBB