CodeIgniter中的Mysql INSERT和SELECT

I have 3 tables a many -to-many,

BOOK

book_id | book_name | rubric | autor

RUBRIC

rubric_id | rubric_name

AUTOR

autor_id | first_name | last_name

I looking for query that select all data in one table. I insert data via form like this:

Controller

public function insert_data_to_db(){

        $form_data_book_name['book_name'] = $this->input->post('book_name');
        $form_data_autor['first_name'] = $this->input->post('first_name');
        $form_data_autor['last_name'] = $this->input->post('last_name');
        $form_data_rubric['rubric'] = $this->input->post('book_rubric');

        $proc = $this->book_model->insert_books_to_db($form_data_book_name);
        if($proc){
            echo "ok";
        }

        $proc1 = $this->book_model->insert_autors_to_db($form_data_autor);
        if($proc1){
            echo "ok";
        }

        $proc2 = $this->book_model->insert_rubric_to_db($form_data_rubric);
        if($proc2){
            echo "ok";
        }
}

MODEL

public function insert_books_to_db($form_data_book_name){
        return $this->db->insert('book',$form_data_book_name);
    }

    public function insert_autors_to_db($form_data_autor){
        return $this->db->insert('autor',$form_data_autor); 
    }

    public function insert_rubric_to_db($form_data_rubric){
        return $this->db->insert('book',$form_data_rubric); 
    }

And to select data I use query in my Model like this:

public function show_book_and_autor_name(){
        $query = $this->db->query("SELECT DISTINCT book.book_name, autor.first_name, autor.last_name, rubric.rubric_id FROM book LEFT JOIN autor ON book.autor=autor_id LEFT JOIN rubric ON book.rubric=rubric_id ORDER BY book.book_id;");
        return $query->result();
    }

How to insert in column autor | rubric some keys with relations with table AUTOR and RUBRIC? And How to select it in right way? Thank you in advance!

In your models you could use the function:

$this->db->insert_id();

to get the inserted ID. You could do:

public function insert_books_to_db($form_data_book_name){
    if ( $this->db->insert('book',$form_data_book_name) )
        return $this->db->insert_id();
}

Read the CodeIgniter Documentation