php - view table joins in codeigniter -
i have 2 tables category table , factory table. in category table have following rows.
idcategory category
in factory table have following rows.
idfactories factoryname postcode country telephone number email website profile adress idcategory
i have table have idfactory , idcategory stored too.
my factorycategories table has following rows.
idfactorycat idfactory idcategory factorycat
i made join in category model because want categories on site , when click on category factories stored in category has show up.
in model have
$this->db->select('*'); $this->db->from('bedrijfcategorieen'); $this->db->join('bedrijfcategorieen', 'bedrijfcategorieen.idbedrijven = bedrijven.idbedrijven'); $this->db->join('bedrijfcategorieen', 'bedrijfcategorieen.idcategorieen = categorieen.idcategorieen'); $query = $this->db->get();
what have store in controller , views? new codeigniter.
ps: translated rows easy understand others because dutch.
thanks
edit: it's bit tricky explain have sidebar catogories.
categories cars cars parts books etc etc...
i want create links each category.
when click on, let's cars. want go results page factories showed have category id=1 because cars has id=1. actual question. , think need join that.
hope understand it.
thanks again.
edit match edit
based on edit, i'm giving basic ideas here. please refer codeigniter manual details:
//model
function getresults($segment3){ $this->db->select('*'); $this->db->from('category'); $this->db->join('factories', 'category.idcategory. ' = factories.idfactories'); $this->db->join('factorycategories', 'factorycategories.idfactory = ' . $segment3); $query = $this->db->get(); return $query->result(); } //note return results match in tables. //if need return more of table, use right join or left join. function categories(){ //call controller create initial links $query = $this->db->get('category'); return $query->result(); }
//controller
function pagecategories(){ // shows initial categories links on page $data["links"] = $this->modelname->categories(); $this->load->view("page-to-view"); } function pagefactories(){ // takes categories , shows factories $this->load->helper('url'); $segment3 = $this->uri->segment(3); $data["results"] = $this->modelname->getresults($segment3); $this->load->view("page-to-view"); }
//view
print_r($results); //run test - debug
show links (note segment pattern):
if(isset($links) && is_array($links)){ foreach($links $k => $value){ echo '<a href="'.base_url().'yourcontroller/pagefactories/'.$value->idcategory.' ">' .$value->category. '</a>'; echo "<br />"; } } if(isset($results ) && is_array($results )){ foreach($results $key => $row){ echo $row->category; echo "<br />"; echo $row->factoryname; //it goes on as want } }
this big picture.
how you'd convert dutch can't figure out. note: google.translate.com mess lots of white spaces might have clean up.
Comments
Post a Comment