View Full Version : SELECT lookup two tables problem...

09-11-2009, 04:26 PM
Hi all;

Iam new in php so I need someone's help.

I Have 2 tables:
categorias - id_cat, nome_cat
catalogo - id, id_cat, nome, img_id, nome, desc, status

My question is this: Iam using this SELECT to get values as describe in the select...but with error's, and I cant fix this.

$sql = "(SELECT id , nome FROM `catalogo`) UNION ( SELECT id , nome_cat FROM `categorias` WHERE id_cat = 'categorias.id_cat')";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))

09-11-2009, 04:48 PM
What errors are you getting? Have you tried that query directly in MySQL?

09-11-2009, 04:49 PM
try this;

SELECT cata.id AS cataID, cata.nome, cate.id AS cateID, cate.nome_cat FROM catalogo cata, categorias cate WHERE cataID = cateID

09-11-2009, 04:53 PM
Thanks a lot guys.

Its working now..

I use this..

$sql = '( SELECT catalogo . * , categorias . * FROM catalogo INNER JOIN categorias WHERE catalogo . id_cat = categorias . id_cat )';