php - How to add multiple images to offers-table using joins? -


i made upload form upload multiple images server. made function in model add file names database, works great. want assign images 1 offer (table in database)

i using table joins add more 1 offer specific company (table in database)

so 1 company can have more offers, offers has more 1 image.

translation: aanbieding means offer, bedrijven means company, foto means image

the current case: there created 3 offers. each image there's offer created, same info, difference image id.

my table joining companies, offers , images looks following:

bedrijfaanbiedingen ------------------- idbedrijfaanbiedingen idbedrijven idaanbiedingen idfotoaanbiedingen idaanbiedingcat 

as can see it's possible have 1 company several offers , several images.

my model adding offer looks this:

public function addaanbieding($image_data = array()) {     $data1 = array(         'aanbieding' => $this->input->post('aanbiedingnaam'),         'tekst' => $this->input->post('aanbiedingomschrijving'),         'prijs' => $this->input->post('aanbiedingprijs'),         'conditie' => $this->input->post('aanbiedingconditie'),         'prijssoort' => $this->input->post('prijsopties'),     );           $this->db->insert('aanbiedingen', $data1);      $aanbiedingid = $this->db->insert_id();     $catid = $this->input->post('categorie');      if($this->db->affected_rows() >= 1)      {          $to_bedrijfaanbiedingen['idaanbiedingen'] = $this->db->insert_id();         $to_bedrijfaanbiedingen['idbedrijven'] = $this->session->userdata('idbedrijven');         $to_bedrijfaanbiedingen['idaanbiedingcat'] = $catid;         $insert_data = array(             'fotonaam' => $image_data['file_name']         );         $input = $this->input->post('userfile');         if(isset($input)){             $this->db->insert('fotoaanbiedingen', $insert_data);         }else{             return false;         }         $fotoid = $this->db->insert_id();          $to_bedrijfaanbiedingen['idbedrijven'] = $this->session->userdata('idbedrijven');         $to_bedrijfaanbiedingen['idaanbiedingen'] = $aanbiedingid;         $to_bedrijfaanbiedingen['idfotoaanbiedingen'] = $fotoid;          $this->insert_bedrijfaanb2($to_bedrijfaanbiedingen);     };  }  public function insert_bedrijfaanb2($data)  {      $this->db->insert('bedrijfaanbiedingen', $data);      return $this->db->affected_rows() >= 1 ? true : false;  } 

i hope it's clear want.

i want 1 offer on 1 company 2 or more images.

edit:

my whole table structure:

bedrijven (companies) --------- idbedrijven bedrijfsnaam profiel plaats telefoonnummer etc...  aanbiedingen (offers) ------------ idaanbiedingen aanbieding prijs conditie etc..  bedrijfaanbiedingen (companyoffers) ------------------- idbedrijfaanbiedingen idbedrijven idaanbiedingen idfotoaanbiedingen idaanbiedingcat  fotoaanbiedingen --------------- idfotoaanbiedingen file_name 

well, it's not entirely clear want (sorry) please forgive me if explaining wrong thing. think trying implement one-to-many relationship in database. best done linking table if number of images arbitrary.
system describe below allow link infinite number of images offers, companies offers , offers companies.

i'm not sure how tables constructed i'll make up:

company (company_id,company_name) image (image_id,image_url) offer (offer_id,offer_details) company_offer (company_offer_id,company_id,offer_id) image_offer (image_offer_id,image_id,offer_id)

image_company (image_company_id,image_id,company_id) //optional if wish images linked companies without having offer.

an offer created. link company offer using company_offer , image offer using image_offer.

the sql along lines of:

select company_name,image_url, {others} company left join company_offer on company.company_id=company_offer.company_id left join image_offer on company_offer.offer_id=image_offer.offer_id left join image on image_offer.image_id = image.image_id {where criteria go here} //note sql untested.

the key happiness here database design. can implement one-to-many relationships if keep data stored in each table minimum (ideally no non-id data in table should duplicated elsewhere) 4th normal form if want know more. make lots of bitty tables , gnarly joins outcome easier system navigate lower storage costs.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -