php - 如何传递数据库数据以在 Codeigniter 中查看输入

标签 php mysql codeigniter

我正在尝试为带有输入复选框的复选框制作编辑按钮

截图:http://gyazo.com/381e44b71e7b62d257bff0a0361b5d61

我已经完成了插入函数及其工作。

在表中我有类似的数据库

 id  property_id  property_type_id     alt_txt  
------  -----------  ----------------  ------------
     1            1                 1        25
     2            2                 1        30
     4            7                 1        50
    49            6                 1        60

property_type_id 与复选框相关,alt_txt 与输入相关

点击编辑时如何将这些数据传递给他们

我试着让模型功能像

function get_by_id($id){
            $this->db->where('id', $id);
            return $this->db->get($this->_table_name);
    }

在 Controller 中我这样调用它

 $this->data['type'] = $this->type_m->get_by_id($id);

在 var_dump 中我收到了

object(CI_DB_mysql_result)#232 (8) {
  ["conn_id"]=>
  resource(45) of type (mysql link)
  ["result_id"]=>
  resource(87) of type (mysql result)
  ["result_array"]=>
  array(0) {
  }
  ["result_object"]=>
  array(0) {
  }
  ["custom_result_object"]=>
  array(0) {
  }
  ["current_row"]=>
  int(0)
  ["num_rows"]=>
  int(0)
  ["row_data"]=>
  NULL
}

请帮我实现这个编辑功能。

编辑:

这是我的 View 代码的一部分:

    <fieldset>
                    <!--        Form Name -->                
                    <legend>Choose property type</legend>

<!--                 Multiple Checkboxes (inline) -->
                <div class="form-group">
                  <div class="col-md-4">
                    <label class="checkbox-inline" for="checkboxes-0">
                    <?php echo form_checkbox('data[1][property_type_id]', '22', set_value('data[1][property_type_id]', $type->property_type_id), 'id="checkboxes-0"')?>
                      PentHause
                    </label>
                      <br>
<!--                 Text input-->
                <div class="form-group">
                  <div class="col-md-8">
                <?php  echo form_input('data[1][alt_txt]', set_value('data[1][alt_txt]',$type->alt_txt), 'class="form-control" id="cena" placeholder="Enter Price"')?>

                  </div>
                </div>

                    <label class="checkbox-inline" for="checkboxes-1">
                <?php echo form_checkbox('data[2][property_type_id]', '21', set_value('data[2][property_type_id]', $type->property_type_id), 'id="checkboxes-1"')?>
                      Garage
                    </label>
                <br>
<!--                                         Text input-->
                <div class="form-group">
                  <div class="col-md-8">
                <?php echo form_input('data[2][alt_txt]', set_value('data[2][alt_txt]', $type->alt_txt), 'class="form-control" id="cena" placeholder="Enter Price"')?>
                  </div>
                </div>

最佳答案

如果您只想让 1 行在您的模型中使用 get_where() 方法,这可能会更容易:

$item = $this->db->get_where($this->_table_name,array("id"=>$id),1,0);

return ($item->num_rows() == 1) ? $item->row() : false;

这样您就可以使用 get_where() 的限制和偏移参数选择 1 行,检查结果是否只有一行并返回该行对象,否则为 false 将导致调用失败。

关于php - 如何传递数据库数据以在 Codeigniter 中查看输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28169749/

相关文章:

php - 更好的想法如何从数据库中获取大量 MySql 数据

mysql - 如何最好地组织我的数据库

php - 了解 php 引用和静态

PHP 从 MySQL 构建一个数组

php - 为什么我的代码没有从我的数据库中发布数据?

Internet Explorer 中的 PHP session 数据更改

php - 对 Codeigniter 登录进行过滤

javascript - 在没有页面刷新的情况下提交表单不起作用

mysql - 如何在 Talend 中将 mysql 数据公开为 SOAP Web 服务

regex - CI 3.0.4 大 where_in 查询导致消息 : preg_match(): Compilation failed: regular expression is too large at offset)