• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
join sql help

#1
[eluser]mattylux[/eluser]
hello

This is my controller and I would like connects the two tables with join sql
but I have never done I'd need some advice.



Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Catalogo extends CI_Controller{

    function __construct(){
        parent:: __construct();
    }

    function index(){    
        $data['title'] = "Catalogo | Strade di carta";
        
        $this->load->view('include/v_header',$data);
        $this->load->view('include/v_menu');
        $this->load->view('v_catalogo');
        $this->load->view('include/v_footer');
    }

    function elenco(){
        $tipo = $this->uri->segment(2);
        $genere = $this->uri->segment(3);
        $catalogo = $this->uri->segment(4);
        $data['titolo'] = "Catalogo > ".ucwords(str_replace("-"," ",$tipo))." > ".ucwords(str_replace("-"," ",$genere))." > ".ucwords(str_replace("-"," ",$catalogo))." | Strade di carta";
        $data['catalogo'] = $catalogo;
        $data['tipo'] = $tipo;
        $data['genere'] = $genere;
      
        
        $this->load->view('include/v_header',$data);
        $this->load->view('include/v_menu');
        $this->load->view('catalogo/v_elenco',$data);
        $this->load->view('include/v_footer');
        
    }
}

?>

the two tables are called for the database catalogo and generi in my library
Table is in the catalog are: id, codice_bilbioteca, autore_nome, autore_cognome, title, series publication.
genres in the table: id and kind. how can I do to relate them

libri_model

Code:
<?php

class Libri_model extends CI_model {
    
    function __construct()
{
    parent:: __construct();
    
}
  
$this->db->select('catalogo.codice_biblioteca, catalogo.autore_nome, catalogo.autore_cognome, catalogo.titolo,catalogo_collana, catalogo.pubblicazione');

thanks

#2
[eluser]osci[/eluser]
since you 've never did a join before I suggest you read PHP Manual - Join.

If you think it's too much read http://www.tizag.com/sqlTutorial/sqljoin.php which covers basic usage, but I still recommend you should read the first too.

#3
[eluser]skeletonfriend[/eluser]
You need to have a foreign key in the Catalog table that references the Genre table in order to make a join.

Code:
$this->db->from('catalogo');
$this->db->join('generi', 'catalogo.generi_id = generi.id');
$result = $this->db->get();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.