Hello!
Im gonna filtering recored from mysql database using dropdown. and when i run the code, i got some error like this :
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/NewTim_Model.php
Line Number: 13
and this is my model :
Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class NewTim_model extends CI_Model {
public function getTim(){
$query = $this->db->get('tim');
if($query->num_rows() > 0){
return $query->result();
}
}
public function getRecords($timid){
$sql = "SELECT karyawan.* FROM tim INNER JOIN karyawan ON tim.tim_id=karyawan.tim_id WHERE tim.tim_id='$timid'";
$d = $this->db->query($sql);
//$data = $d->result();
$data=$d->row_array();
return $data;
}
}
my controller :
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Tim extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('Tim_Model');
$this->load->model('NewKaryawan_model');
$this->load->model('NewTim_Model');
$this->base=$this->config->item('base_url');
}
public function index()
{
$getTim = $this->NewTim_Model->getTim();
$this->load->view('Tim/tim_list', ['getTim'=> $getTim]);
}
public function getRecords(){
$this->load->model('NewKaryawan_model');
$this->load->model('Tim_Model');
$anggotaTim = $this->input->post('tim_id');
$getTim=$this->NewTim_Model->getTim();
//$getAnggota = $this->NewKaryawan_model->getNamaKaryawan();
$records = $this->NewTim_Model->getRecords($getTim);
$this->load->view('Tim/tim_list', ['getTim' => $getTim, 'records' => $records]);
}
my view
Code:
<?php $this->load->view('templates/header_manajer');?>
<div class="row" style="margin-bottom: 10px">
<div class="col-md-4">
<h2 style="margin-top:10px">Data Tim</h2>
</div>
<div class="col-md-4 text-right">
<?php echo anchor(site_url('Tim/create'), 'Tambah', 'class="btn btn-primary"'); ?>
</div>
</div>
<div class="panel-body">
<table class="table table-bordered table-striped" id="mytable">
<?php echo form_open('Tim/getRecords')?>
<tr>
<td> ID</td>
<td>
<select class="form-control" name="tim_id" id="tim_id"><br>
<?php if(count($getTim)):?>
<?php foreach ($getTim as $tim): ?>
<option value="<?php echo $tim->tim_id;?>"> <?php echo $tim->tim_id;?> </option>
<?php endforeach;?>
<?php else:?>
<?php endif;?>
</select>
</td>
</tr>
<tr><td><?php echo form_submit(['name'=>'submit', 'value'=>'Records'])?></td></tr>
<?php echo form_close()?>
<tr>
<td> Anggota</td>
<?php if(count($records)): ?>
<?php foreach($records as $rec):
//$kr_nama=$j['kr_nama'];
//$tim_anggota=$i['tim_anggota'];
?>
<td><?php echo $rec->kr_nama;?></td>
<tr><td><?php endforeach;?> </td></tr>
</tr>
<?php else:?>
<tr><td>No record founds!</td></tr>
<?php endif;?>
<tr><td> Action</td><td><a href="<?php echo base_url()."index.php/Tim/getTimID/".$i['tim_id']; ?>" class="btn btn-default btn-sm">Ubah</a> | <a href="<?php echo base_url()."index.php/Tim/deleteTim/".$i['tim_id']; ?>" class="btn btn-default btn-sm">Hapus</a> </td> </tr>
</table>
</div>
</div>
<?php $this->load->view('templates/footer'); ?>
and my table on the attachment
please tell me what sholud i do with this code, thank you