我在CI視圖頁面中獲取錯誤,因爲爲foreach()提供了無效參數。 這是我的代碼:在codeigniter(皇冠)中爲foreach提供的無效參數
我的數據庫:
**id_penyewa
nama_penyewa
alamat
no_telp**
(Jaminan表)
**id_penyewa
jenis_jaminan
ket_jaminan**
在控制器
(Penyewa表)(penyewa.php )
function Penyewa()
{
parent::Controller();
$this->load->database();
$this->load->model('model_tampil');
}
function tambah()
{
$ck=$this->input->post('id_penyewa');
if($ck!='')
{
$this->model_tampil->insertPenyewa();
}
$this->load->view('tampilpenyewa');
}
function sukses()
{
echo "Data berhasil di input!";
?>
<br />
<a href="<?php echo base_url();?>/index.php/login/input_penyewa">Tambah Data</a>
<br />
<a href="<?php echo base_url();?>/index.php/login/tampil_penyewa">Lihat Data</a>
<?php
}
在模型(model_tampil.php)
function getPenyewa(){
$this->db->select('*');
$this->db->from('penyewa');
$this->db->join('jaminan','jaminan.id_penyewa = penyewa.id_penyewa');
$q = $this->db->get();
$rows = $q->num_rows();
$q_result = $q->result();
if($rows>0){
foreach($q_result as $row){
$data[] = $row;
}
return $data;
}
}
function insertPenyewa()
{
/*$this->db->trans_start();
$this->db->query('INSERT INTO penyewa VALUES($id_penyewa, $nama_penyewa, $alamat, $no_telp, $jenis_jaminan)');
$table1_id = $this->db->insert_id();
$this->db->query('INSERT INTO jaminan VALUES(id_penyewa,' . $table1_id .',jenis_jaminan)');
$this->db->trans_complete(); */
$this->id_penyewa=$this->input->post('id_penyewa');
$this->nama_penyewa=$this->input->post('nama_penyewa');
$this->alamat=$this->input->post('alamat');
$this->no_telp=$this->input->post('no_telp');
$this->jenis_jaminan=$this->input->post('jenis_jaminan');
$this->db->insert('penyewa',$this);
redirect('penyewa/sukses');
}
在次(tampilPenyewa.php)
<center> <h3>Tabel data Penyewa</h3> <table border="1"> <tr align="center" bgcolor="#33CC99"> <td width="100">ID Penyewa</td> <td width="200">Nama Penyewa</td> <td width="120">Alamat</td> <td width="150">Nomor Telepon</td> <td width="150">Jenis Jaminan</td> <td>Tindakan Lanjut</td> </tr> <?php foreach ($records as $row) : ?> <tr height="35"> <td> <?php echo $row->id_penyewa; ?></td> <td> <?php echo $row->nama_penyewa; ?></td> <td> <?php echo $row->alamat; ?></td> <td> <?php echo $row->no_telp; ?></td> <td> <?php echo $row->ket_jaminan; ?></td> <td></td> </tr> <?php endforeach; ?> </table> <br /> <a href="<?php echo base_url();?>/index.php/login/input_penyewa">Tambah Data</a>
和在視圖中太(inputpenyewa .php)
<center> <?php $this->load->library('validation'); $id_penyewa=array( 'name' => 'id_penyewa', 'id' => 'id_penyewa', 'value' => '', 'maxlength' => '100', 'size' => '50', 'validation' => "required"); $nama_penyewa=array( 'name' => 'nama_penyewa', 'id' => 'nama_penyewa', 'value' => '', 'maxlength' => '100', 'size' => '50', 'validation' => "required"); $alamat=array( 'name' => 'alamat', 'id' => 'alamat', 'value' => '', 'maxlength' => '500', 'size' => '', 'validation' => "required"); $no_telp=array( 'name' => 'no_telp', 'id' => 'no_telp', 'value' => '', 'maxlength' => '100', 'size' => '50', 'validation' => "required"); $ket_jaminan=array( 'name' => 'jenis_jaminan', 'id' => 'jenis_jaminan', 'value' => '', 'maxlength' => '100', 'size' => '50', 'validation' => "required"); $this->load->helper('form'); echo validation_errors(); echo form_open('penyewa/tambah'); echo '<center><h3>Input Data Penyewa</h3></center>'; echo "<table border='0' class='tabledetail' align='center'>"; echo "<tr>"."<td>".form_label('ID')."</td>"."<td>".form_input('id_penyewa')."</td>"."</tr>"; echo "<tr height=50>"."<td>".form_label('Nama Penyewa')."</td>"."<td>".form_input('nama_penyewa')."</td>"."</tr>"; echo "<tr height=220>"."<td>".form_label('Alamat')."</td>"."<td>".form_textarea('alamat')."</td>"."</tr>"; echo "<tr>"."<td>".form_label('No Telp')."</td>"."<td>".form_input('no_telp')."</td>"."</tr>"; echo "<tr height=220>"."<td>".form_label('Jaminan')."</td>"."<td>".form_textarea('jenis_jaminan')."</td>"."</tr>"; echo "<tr height=50>"."<td colspan=2 align='center'>".form_submit('mysubmit','Simpan')."</td>"."</tr>"; echo "</table>"; echo form_close(); ?> <a href="<?php echo base_url();?>/index.php/login/tampil_penyewa">Lihat Data</a>
好吧,我很抱歉,如果我的問題是非常多,多.. 謝謝:)
更新:
好,我這樣做,但沒有結果,我的網頁錯誤再次..
和,我想再次問,model_tampil-> getPenyewa()??中的任何錯誤?
這是腳本:
function getPenyewa(){
$this->db->select('*');
$this->db->from('penyewa');
$this->db->join('jaminan','jaminan.id_penyewa = penyewa.id_penyewa');
$q = $this->db->get();
$rows = $q->num_rows();
$q_result = $q->result();
if($rows>0){
foreach($q_result as $row){
$data[] = $row;
}
return $data;
}
}
我想將數據輸入到2臺在我的本地主機,從第1頁,inputpenyewa.php ..
請張貼只是相對的代碼而不是整個事情 –
哪裏是你'$ records'一套....我敢打賭,這裏的問題是造成由'$ records' ... – bipen