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


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.

<?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";

    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;


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



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');


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.

You need to have a foreign key in the Catalog table that references the Genre table in order to make a join.

$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.