Welcome Guest, Not a member yet? Register   Sign In
Help novice !
#1

[eluser]Unknown[/eluser]
Hello !
I have next tables :
Code:
CREATE TABLE authors (id_author int(8) PRIMARY KEY auto_increment,
                        firstName VARCHAR(40),
                        lastName VARCHAR(40));
                        
CREATE TABLE genres (id_genre tinyint(2) PRIMARY KEY auto_increment,
                        title VARCHAR(40));        
                        
CREATE TABLE books(ISBN int(8) PRIMARY KEY auto_increment,
                    title VARCHAR(100),
                    image MEDIUMBLOB) ENGINE = FILES;
                    
CREATE TABLE books_author(ISBN int(8),
                            id_author int(8));
                            
CREATE TABLE books_genre(ISBN int(8),
                            id_genre int(8));

How can i display all the data from the table 'Books' (include data from 'books_genre', 'books_author') with the replacement 'ID's' with their titles ? Hopefully clearly explained Smile
Thank you very much !
#2

[eluser]Otemu[/eluser]
Hi,

You will need to use a join, something like the Query below:

Code:
$this->db->select('books.title, image, firstName, lastName, genres.title ');
$this->db->from('books');
$this->db->join('books_author', 'books.ISBN = books_author.ISBN ');
$this->db->join('books_genre', 'books.ISBN = books_genre.ISBN ');
$this->db->join('authors', 'authors.id_author = books_author.id_author');
$this->db->join('genres', genres.id_genre = books_genre.id_genre');
$query = $this->db->get();
#3

[eluser]Unknown[/eluser]
Thank you !




Theme © iAndrew 2016 - Forum software by © MyBB