Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2009
    Location
    Portugal/Porto
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Lightbulb SELECT lookup two tables problem...

    Hi all;

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

    I Have 2 tables:
    categorias - id_cat, nome_cat
    and
    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))

  • #2
    New Coder
    Join Date
    Aug 2009
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    What errors are you getting? Have you tried that query directly in MySQL?

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    try this;

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

  • #4
    New Coder
    Join Date
    Sep 2009
    Location
    Portugal/Porto
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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 )';


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •