Hello,
i have 2 tables, socios and socios_img, it’s a db for members of car club.
The first table is where i have the id, name, make(of the car), year and a little text.
The second table i have id, id_socio(the same number of the 1st table so i can join them) and then i have foto_thumb and foto_big.
Now i wanted to do a query where the result would be: id, name, foto_thumb(only the first foto from that specific member).
Basicly i want to display everything from the first table but with an image from the car of the member, but the pictures are only on the second table… and i want only the first picture from each member because the second table has more than 1 picture from each member
I hope i explain everything clear
CREATE TABLE `socios` (
`id` tinyint(4) NOT NULL auto_increment,
`nome` tinytext collate latin1_bin NOT NULL,
`carro` tinytext collate latin1_bin NOT NULL,
`ano` tinytext collate latin1_bin NOT NULL,
`texto` text collate latin1_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=3 ;
CREATE TABLE `socios_img` (
`id` tinyint(4) NOT NULL auto_increment,
`id_socio` tinyint(4) NOT NULL default '0',
`foto_thumb` tinytext collate latin1_bin NOT NULL,
`foto_big` tinytext collate latin1_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_bin AUTO_INCREMENT=16 ;
let me give you an example:
table socios:
id | nome | carro | ano | texto
1 | Rogério Machado | Fiat 600D | 1970 | É amarelo e é muito giro
2 | Margarida | fiat 600 | 1960 | vermelho descapotavel
table socios_img
id | id_socio | foto_thumb | foto_big
15 | 2 | img/socios/thumb_2_Tras.jpg | img/socios/big_2_Tras.jpg
14 | 2 | img/socios/thumb_2_Por do sol.jpg | img/socios/big_2_Por do sol.jpg
13 | 1 | img/socios/thumb_1_Nenufares.jpg | img/socios/big_1_Nenufares.jpg
11 | 1 | img/socios/thumb_1_Inverno.jpg | img/socios/big_1_Inverno.jpg
as you see the user rogerio has on db socios_img 2 images… (id 15 and id 14)
user margarida has on db socios_img 2 images too…(id 13 and id 11)
I want to have as result:
1 | Rogério Machado | Fiat 600D | 1970 | É amarelo e é muito giro | 15 | 2 | img/socios/thumb_2_Tras.jpg | img/socios/big_2_Tras.jpg
2 | Margarida | fiat 600 | 1960 | vermelho descapotavel | 13 | 1 | img/socios/thumb_1_Nenufares.jpg | img/socios/big_1_Nenufares.jpg
an nothing else.
How can i do this?