Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP致命错误:对中的非对象调用成员函数row()_Php_Codeigniter - Fatal编程技术网

PHP致命错误:对中的非对象调用成员函数row()

PHP致命错误:对中的非对象调用成员函数row(),php,codeigniter,Php,Codeigniter,你能帮我写代码吗?我是php和codeigniter的新手,我正在尝试获取对视图的查询结果,但总是出现错误“致命错误:对中的非对象调用成员函数行()”,我正在尝试按客户id搜索客户信息,并尝试将结果获取到视图本身 这是查看代码 <?php echo form_open('home/cari_id'); ?> <table width='34%' align='left'> <tr> <td width="54%" align="

你能帮我写代码吗?我是php和codeigniter的新手,我正在尝试获取对视图的查询结果,但总是出现错误“致命错误:对中的非对象调用成员函数行()”,我正在尝试按客户id搜索客户信息,并尝试将结果获取到视图本身

这是查看代码

 <?php echo form_open('home/cari_id');
?>
<table width='34%' align='left'>
    <tr>
        <td width="54%" align="left">ID Pelanggan</td>

        <td width="36%">
            <?php echo form_input('id',set_value('id'));?>
            <?php echo form_error('id');?>
        </td>
        <td width="10%">
            <?php echo form_submit('submit','Cari');?>
        </td>
    </tr>
</table> 

<br /><br />

<table width="68%" align="left">
    <tr>
        <td width="17%" align="left">Nama</td>
        <td>
            <?php   
                $row = $record->row();
                $nama1 = array(
                         'name' => 'nama',
                         'maxlength' => '100',
                         'size' => '50',
                         'style' => 'width:120%');
                echo form_input($nama1,$row->nama);?>
            <?php echo form_error('nama');?>
        </td>
    </tr>
    <tr>
    <td align="left">Alamat</td>
    <td>
        <?php 
            $alamat1 = array(
                        'name' => 'alamat',
                        'rows' => '5',
                        'cols' => '3',
                        'style' => 'width:200%');
            echo form_textarea($alamat1,$row->alamat);?>
        <?php echo form_error('alamat');?>
    </td>
    </tr>
    <tr>
        <td align="left">Golongan</td>
        <td width='29%'>
            <?php 
                $gol1 = array(
                        'name' => 'gol',
                        'maxlength' => '100',
                        'size' => '50',
                        'style' => 'width:40%');
                echo form_input($gol1,$row->golongan);?>
            <?php echo form_error('gol');?>
        </td>
        <td width="10%" align="left">Tarif</td>
        <td width="44%">
            <?php 
                $tarif = array(
                'name' => 'tarif',
                'maxlength' => '100',
                'size' => '50',
                'style' => 'width:30%');
                echo form_input($tarif,$row->tarif);?>
            <?php echo form_error('tarif');?>
        </td>
    </tr>
</table>

谢谢,请在控制器中写下这封信

public function cari_id()
{
    $this->auth->restrict();
   // mencegah user mengakses menu yang tidak boleh ia buka
    $this->auth->cek_menu(4);

    $this->load->library('form_validation');

    $this->form_validation->set_rules('id', 'ID Pelanggan', 'trim|required');
    //$this->form_validation->set_rules('nama','Nama','trim'|'required');
    //$this->form_validation->set_rules('alamat','Alamat','trim'|'required');
    //$this->form_validation->set_rules('gol', 'Golongan', 'trim|required');
    //$this->form_validation->set_rules('tarif', 'Tarif', 'trim|required');
    $this->form_validation->set_error_delimiters(' <span style="color:#FF0000">', '</span>');
    $id_pel = $this->input->post('id') ;
    //$data1 = $this->usermodel->get_list_bayar_pel($id_pel);
    //$data=$data1->row();
    $data1 = $this->usermodel->get_list_bayar_pel($id_pel);
    $data['record'] = $query->result_array();
    $this->template->set('title','Input Pembayaran | POS Application');
    $this->template->load('template','admin/input_pembayaran',$data);

}
$data['record'] = $query->row();
并在视图中删除 php代码编写

 <?php   

                $nama1 = array(
                         'name' => 'nama',
                         'maxlength' => '100',
                         'size' => '50',
                         'style' => 'width:120%');
                echo form_input($nama1,$record->nama);?>
            <?php echo form_error('nama');?>

$record没有返回单行,它返回的是一个集合使用当前($record)->row()或获取单行。

在控制器中,您获取的是多行

$data['record'] = $query->result_array();
应该是

$data['record'] = $query->row();

并在视图中给出$row=$record;而不是$row=$record->row()

根据您的代码,您使用row()函数在视图中检索数据,同时在控制器中使用以下方法获取数据:

 $data['record'] = $query->result_array();

只需使用其中一个(在控制器中):

然后在视图中处理数组

希望有帮助:)


注:
-我建议您使用result_array()将数据检索到数组中

$data['record'] = $query->row();
 $data['record'] = $query->result_array();
$data['record'] = $query->result_array();
$data['record'] = $query->row();