kunitsuji
tsuji****@m-s*****
2008年 7月 11日 (金) 14:58:17 JST
kunitsujiです。
ちょっと長くなりますが、どうだろうかと。
分けて送ります。
まずはコントローラー
<?php
class Custmer extends Controller {
function Custmer()
{
parent::Controller();
}
function edit($cu_id = '')
{
//まず入力をさせる
$cu_id = intval($cu_id);
$this->db->where(array('cu_id'=>($cu_id)));
$query = $this->db->get('custmer');
if ($query)
{
$row = $query->row();
$data['cu_id'] = $row->cu_id;
$data['cu_name'] = $row->cu_name;
$data['cu_kana'] = $row->cu_kana;
$data['cu_tel'] = $row->cu_tel;
$data['cu_fax'] = $row->cu_fax;
$data['cu_mail'] = $row->cu_mail;
$data['biko'] = $row->biko;
$data['datetime'] = $row->datetime;
$data['msg'] = '入力してください。';
$data['err_flag'] = FALSE; //エラーはない
}
else
{
//指定のIDが見つからなかった場合
$data['msg'] = '<span style="color:red">指定のIDではデータが
見つかりませんでした。</span>';
$data['err_flag'] = TRUE; //エラーとする
}
$this->load->view('custmer_edit', $data);
}
//edit_confirm
functino edit_confirm()
{
if ($this->input->post('submit') == '戻る')
{
//入力画面へ戻る
$cu_id = intval($cu_id);
$this->db->where(array('cu_id'=>($cu_id)));
$query = $this->db->get('custmer');
if ($query)
{
$row = $query->row();
$data['cu_id'] = $row->cu_id;
$data['cu_name'] = $row->cu_name;
$data['cu_kana'] = $row->cu_kana;
$data['cu_tel'] = $row->cu_tel;
$data['cu_fax'] = $row->cu_fax;
$data['cu_mail'] = $row->cu_mail;
$data['biko'] = $row->biko;
$data['datetime'] = $row->datetime;
$data['msg'] = '入力してください。';
$data['err_flag'] = FALSE; //エラーはない
}
else
{
//指定のIDが見つからなかった場合
$data['msg'] = '<span style="color:red">指定のIDではデー
タが見つかりませんでした。</span>';
$data['err_flag'] = TRUE; //エラーとする
}
$this->load->view('custmer_edit', $data);
}
else
{
$data = array(
'cu_id' => $this->input->post('cu_id'),
'cu_name' => $this->input->post('cu_name'),
'cu_kana' => $this->input->post('cu_kana'),
'cu_tel' => $this->input->post('cu_tel'),
'cu_fax' => $this->input->post('cu_fax'),
'cu_mail' => $this->input->post('cu_mail'),
'biko' => $this->input->post('cu_biko'),
'datetime' => date('Y-m-d H:i:s', time()), //更新日付
に変えてみる
);
$this->load->view('custmer_edit_confirm', $data);
}
}
function edit_post()
{
$where = array('cu_id' => $this->input->post('cu_id'));
$data = array(
'cu_id' => $this->input->post('cu_id'),
'cu_name' => $this->input->post('cu_name'),
'cu_kana' => $this->input->post('cu_kana'),
'cu_tel' => $this->input->post('cu_tel'),
'cu_fax' => $this->input->post('cu_fax'),
'cu_mail' => $this->input->post('cu_mail'),
'biko' => $this->input->post('cu_biko'),
'datetime' => date('Y-m-d H:i:s', time()), //更新日付
に変えてみる
);
$this->db->update('custmer', $data, $where);
redirect('custmer');
}
}
?>