googleapis / google-api-php-client

A PHP client library for accessing Google APIs
http://googleapis.github.io/google-api-php-client/
Apache License 2.0
9.35k stars 3.53k forks source link

PHP CodeIginter Error : Message: Array to string conversion #1497

Closed sylviadiva closed 6 years ago

sylviadiva commented 6 years ago

Hello, im gonna filter record from mysql database using dropdown in codeigniter and i got some error

A PHP Error was encountered
Severity: Notice

Message: Array to string conversion

Filename: models/NewTim_Model.php

Line Number: 13

this is my model

<?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;
    }
    }

this is my controller

<?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]);

    }

and this is my view

<?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 a

can anyone help me with this error code? thankyou

mattwhisenhunt commented 6 years ago

:wave: Hi @sylviadiva Is this question somehow related to the SQLAdmin API and this (google-api-php-client) library?

If so please include a code snippet that isolates the behavior of this library. Thanks.

mattwhisenhunt commented 6 years ago

Thank you for filing this issue. We asked some clarifying questions or suggested a course of action a week or more ago and never heard back from you. We are unable to proceed with this issue until then, so we are closing it. Please feel free to comment with more information and we will re-open this issue.