在Codeiginter

时间:2015-10-26 09:28:05

标签: php html mysql css codeigniter

您好我有一个搜索结果页面,可以输出我想要的所有信息,但我只有一个小问题,我没有检索到“属性”的图像。目前我的数据库有一个属性表和一个property_images表,有关该属性的所有信息都存储在属性表中,而图像存储在property_images表中。

我的上传功能使用insert_id将图像添加到指定的property_images表并将其链接到属性。

我的问题是这个,如果我在属性表中创建一个property_image字段,我怎样才能让输出只显示property_image表中的一个图像,或者我如何将image_id添加到属性表中以便我可以输出我的搜索中有一张图片?

这是我的搜索代码:

    function get_search(){
        $property_location = $this->input->post('property_location');
        $property_bedroom = $this->input->post('property_bedroom');
        $property_bathroom = $this->input->post('property_bathroom');
        $property_status = $this->input->post('property_status');
        $property_type = $this->input->post('property_type');

        $this->db->like('property_location',$property_location);
        $this->db->like('property_beds',$property_bedroom);
        $this->db->like('property_bath',$property_bathroom);
        $this->db->like('property_state',$property_status);
        $this->db->like('property_type',$property_type);
        $query = $this->db->get('property');
        error_log($this->db->last_query());
    return $query->result();
}

我的上传代码

 private function setup_upload_option()
{
    $config = array();
    $config['upload_path'] = './data/images/property_images';
    $config['allowed_types'] = 'jpg|png|gif';
    $config['encrypt_name'] = TRUE;
    $config['overwrite'] = FALSE;
    return $config;
}

function create_property()
{
    $this->check_is_validated();
    $data['error'] = array('error' => '');
    $files = $_FILES;
    $prop = array(
        'property_ref' => $this->input->post('property_ref'),
        'property_name' => $this->input->post('property_name'),
        'property_slug' => $this->input->post('property_slug'),
        'property_type' => $this->input->post('property_type'),
        'property_state' => $this->input->post('property_state'),
        'property_price' => $this->input->post('property_price'),
        'property_address' => $this->input->post('property_address'),
        'property_description' => $this->input->post('property_description'),
        'active' => 1
    );

    $cap = $this->db->insert('property', $prop);
    $id = $this->db->insert_id();

    if ($cap > 0) {

        $count = count($_FILES['userfile']['name']);
        for ($i = 0; $i < $count; $i++) {
            $_FILES['userfile']['name'] = $files['userfile']['name'][$i];
            $_FILES['userfile']['type'] = $files['userfile']['type'][$i];
            $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
            $_FILES['userfile']['size'] = $files['userfile']['size'][$i];
            $_FILES['userfile']['error'] = $files['userfile']['error'][$i];

            $this->upload->initialize($this->setup_upload_option());
            if ($this->upload->do_upload() == FALSE) {
                $data['error'] = $this->upload->display_errors();
                $data['title'] = 'Create a New Property';
                $data['content'] = 'admin' . '/property/create_new_property';
                $this->load->view('templates/dashboard/template', $data);
            } else {
                $upload_data = $this->upload->data();
                $data = array(
                    'image_id' => $id,
                    'image_name' => $upload_data['file_name'],
                    'image_size' => $upload_data['file_size'],
                    'image_ext' => $upload_data['file_ext'],
                    'full_path' => $upload_data['file_path']
                );
                $this->db->insert('property_images', $data);
            }
        }
        redirect(base_url() . 'admin/properties');
    }
}

0 个答案:

没有答案