liaomars 发表于 2011-1-6 17:38:39

数据传值问题

这个是编辑页的控制器方法
function updata_message($id) {
      $this->load->model("Feed");
      $query = $this->db->get_where('feed', array('id' => $id));
      $data['row'] = $query->result();
      //print_r($data['rs']);
      $data['title'] = "留言编辑";
      $data['include'] = "head";
      $this->load->view('updata_message', $data);
    }



这下面是编辑的视图页
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title><?php echo $title;?></title>
      <base href="<?php echo base_url();?>"/>
      <style type="text/css">
            body{ margin:0px; padding:0px; font-size:12px; font-family:微软雅黑,Verdana, Geneva, sans-serif;}
            div,ul,li,form,dl,dt,dd,table,td{margin:0px; padding:0px; }
            .feed{ width:800px; margin:0 auto; }
            .nav{ height:30px; line-height:30px; background:#9a9898; width:800px; overflow:hidden; margin-top:5px;}
            .nav ul li{ float:left; width:90px; text-align:center; display:block; font-size:14px;}
            .table{border:solid 1px #ccc; border-collapse: collapse; }
            .table td{border:solid 1px #ccc; }
      </style>
    </head>

    <body>
      <div class="feed">
            <?php $this->load->view($include);?>
            <?php
            echo form_open('feedback/send');
             ?>
            <?php
                $rs=$row;
                print_r($rs);
            ?>
            <table border="0" cellpadding="0" cellspacing="0" width="400" align="center">
             <tr>
               <td height="30"><?phpecho form_label("你的姓名","姓名"); ?></td>
               <td><?php   $name = array(
                  'name'      => 'title',
                  'id'          => 'username',
                     'value'=>$rs['title']

            );
            echo form_input($name);?></td>
             </tr>
            <tr>
               <td height="30"><?phpecho form_label("你的留言内容","内容"); ?></td>
               <td><?php   $content=array('name'=>'content','id'=>'content','rows'=>5,'cols'=>50, 'value'=>$rs->content);
            echo form_textarea($content)."<br/>";?></td>
             </tr>
            <tr>
               <td height="30"><?phpecho form_label("你的邮箱","邮箱");?></td>
               <td><?php   $email=array('name'=>'email','id'=>'email', 'value'=>$rs->email);
            echo form_input($email);?></td>
             </tr>
            <tr>
                  <td><?php echo form_submit("submit","提交");?></td>
               <td></td>
             </tr>
         </table>
            <?php echo form_close();?>
      </div>
    </body>
</html>


我现在把$data['row']传到视图页的$rs   但是我打印这个数组的时候出现这个问题Array ( => stdClass Object ( => 1 => liao => fjlksjflksjdlk => liao@163.com => 2010-12-13 20:57:51 => 127.0.0.1 ) )

页面提示这样错误

Hex 发表于 2011-1-6 19:10:43

你取的是对象,而你视图里使用的是关联数组。
所以,你需要改成取关联数组:
$data['row'] = $query->row_array();
还有,你代码里取的是所有记录,而不是一行记录,所以返回的是一维数组,用上面的才是取一行数据,返回一个关联数组。
另外,你的视图里有用$rs['title'],有用 $rs->xxx
这样不行,必须统一成一种,建议使用 $rs['xxxx']

参考:http://codeigniter.org.cn/user_guide/database/results.html

liaomars 发表于 2011-1-6 19:43:20

回复 2# Hex


    多谢,Hex解决!
页: [1]
查看完整版本: 数据传值问题