Lógica correta? Joins?
Bem fiz uma pesquisa detalhada no fórum, mas não consegui achar a solução.
Tenho noção em trabalhar com relacionamento de tabelas, mas nao to conseguindo relacionar mais de duas.
Segue SQL:
CREATE TABLE `banda` (
`banda_id` int(11) NOT NULL auto_increment,
`bd_nome` text NOT NULL,
`bd_release` text NOT NULL,
`estilo_id` int(11) NOT NULL,
`bd_telefone` text NOT NULL,
`bd_email` text NOT NULL,
`bd_site` text NOT NULL,
`bd_capa` varchar(150) NOT NULL,
`bd_status` text NOT NULL,
`contbanda` text NOT NULL,
`bd_filiacao` date NOT NULL,
PRIMARY KEY (`banda_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3;
CREATE TABLE `comentarios` (
`coments_id` int(11) NOT NULL auto_increment,
`cm_comentario` text NOT NULL,
`cm_data` timestamp NOT NULL default CURRENT_TIMESTAMP,
`banda_id` int(11) NOT NULL,
`cm_aprovado` text NOT NULL,
PRIMARY KEY (`coments_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE `estilos` (
`estilos_id` int(11) NOT NULL auto_increment,
`estilo` text NOT NULL,
PRIMARY KEY (`estilos_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12;
CREATE TABLE `fotos` (
`foto_id` int(11) NOT NULL auto_increment,
`foto` text NOT NULL,
`banda_id` int(11) NOT NULL,
`contfoto` text NOT NULL,
PRIMARY KEY (`foto_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE `integrantes` (
`int_id` int(11) NOT NULL auto_increment,
`int_nome` text NOT NULL,
`int_instrumento` text NOT NULL,
`int_foto` text NOT NULL,
`int_email` text NOT NULL,
`int_site` text NOT NULL,
`int_nascimento` text NOT NULL,
`int_influencias` text NOT NULL,
`int_release` text NOT NULL,
`banda_id` text NOT NULL,
PRIMARY KEY (`int_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4;
CREATE TABLE `musicas` (
`musica_id` int(11) NOT NULL auto_increment,
`pl_musica` text NOT NULL,
`banda_id` int(11) NOT NULL,
PRIMARY KEY (`musica_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE `videos` (
`video_id` int(11) NOT NULL auto_increment,
`vd_url` varchar(150) NOT NULL,
`banda_id` int(11) NOT NULL,
`vd_descricao` text NOT NULL,
PRIMARY KEY (`video_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
A parte de cadastrar, editar e deletar do BD, sem problemas, mas a página q irá exibir dados da banda que to com dificuldades. A lógica é a seguinte:
A banda possui um estilo musical (associar estilo e banda consegui fazer)
mysql_select_db($database_conexao, $conexao);
$query_rs1 = sprintf("SELECT * FROM banda INNER JOIN estilos ON banda.estilo_id = estilos.estilos_id WHERE banda_id = %s", $colname_rs1);
Mas prescaria fazer as seguinte conexões também:
- Exibir as fotos que tenham a id da banda.
- Exibir os videos e musicas da Banda.
- Exibir os integrantes da banda.
- Exibir os comentários da banda.
Ai que nao conseguindo, fazer uma relação maior.. sempre dá erro.
Alguém pode me ajudar? Como seria essa relação.
Discussão (4)
Carregando comentários...