牧尾竜一
ryuic****@jom*****
2008年 7月 17日 (木) 23:28:27 JST
JOMRです。
丁寧なご回答いつもありがとうございます。
> これは、単純に$row->redateの中身がひょうじされていると考えられます。
> 日付形式ではなく、timestampではないでしょうか?DBのカラムの定義。
DBのカラムの定義はtimestampです。
> $data['redate_post'] = "なにか";
> っていうのがないので、
> <?=form_prep($redate_post);?>
> ではエラーですね。
> ここでは
> <?=form_prep($redate_item');?>
> とするのが正しいのではないでしょうか?
変更しました。
> echo ではなく
> return としなければなりません。
これは完全にPHPのそのものの勉強不足です。
returnとする事で結果を返せるという解釈でいいのでしょうか?
まとめると
モデルに
function get_computer_redate($cu_id)
{
$this->db->where('cu_id', $cu_id);
$query = $this->db->get('computer');
$row = $query->row();
if ($row->redate == NULL){
return FALSE;
}
else
{
return $row->redate;
}
}
コントローラーに
function pc_list($cu_id = '')
{
//3つ目のセグメントよりcu_idを取得
$data['cu_id'] = (int) $this->uri->segment(3, 0);
$this->db->order_by('cu_id', 'desc');
$this->db->where(array('cu_id'=>($cu_id)));
$query = $data['pc_query'] = $this->db->get('computer');
$redate_post = $this->Customer_model->get_computer_redate($cu_id);
if ($query)
{
$row = $query->row();
$data['pc_id'] = $row->pc_id;
$data['pc_host'] = $row->pc_host;
$data['msg'] = $this->edit_message;
$data['err_flag'] = FALSE; //エラーはない
}
else
{
//指定のIDが見つからなかった場合
$data['msg'] = $this->edit_error_message;
$data['err_flag'] = TRUE; //エラーとする
}
if($redate_post)
{
$data['redate_item'] = $redate_post;
}
else
{
$data['redate_item'] = 'なし';
}
$this->load->view('pc_list', $data);
}
ビューに
<?php foreach($pc_query->result() as $row): ?>
<tr>
<td class="cstd_List_Name">
<?=form_prep($row->pc_host);?></td>
<td class="cstd_List_Name">
<?=form_prep($row->pc_ip);?>
</td>
<td class="cstd_List_Name">
<?=form_prep($row->datetime);?>
</td>
<td class="cstd_List_Name">
<?=form_prep($redate_item);?>
</td>
<td class="cstd_List_Detail">
<?=form_open('customer/pc_detail/'. $row->pc_id);?>
<input type="hidden" name="cu_id" value="<?=form_prep($cu_id);?>">
<input type="submit" value="詳細" class="Confirm" />
<?=form_close();?>
</td>
</tr>
<?php endforeach; ?>
としました。結果エラーはなく表示するのですが変更すると登録されているPCの
変更日全てが変更されてしまいました。
ということは編集の動作がおかしいと判断したらいいのでしょうか?