SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: join question

Hybrid View

  1. #1
    Resistance is Futile webgodjj's Avatar
    Join Date
    Nov 2002
    Location
    Madison, WI USA
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    join question

    I have three tables in mysql that I am trying to query with php. I am horible with joins and need to figure out how to format like below. I think I need two queries.. one to grab the subtitle and one to grab the list of link, right? How do I go about this...

    Prefered output:
    HTML Code:
    <TD>
    <B><a href="suburl.sub_category">subtitle.sub_category</a></B>
    <BR><BR>
    <a href="link_url.sub_category_links">link_title.sub_category_links</a><BR>
    <a href="link_url.sub_category_links">link_title.sub_category_links</a><BR>
    ...



    Code:
    +-----------------+--------------+------+-----+---------+-------+
    | Field           | Type         | Null | Key | Default | Extra |
    +-----------------+--------------+------+-----+---------+-------+
    | pid             | int(11)      |      | PRI | 0       |       |
    | maintitle       | varchar(60)  |      |     |         |       |
    | maindescription | text         | YES  |     | NULL    |       |
    | mainphoto       | varchar(100) | YES  |     | NULL    |       |
    +-----------------+--------------+------+-----+---------+-------+
    4 rows in set (0.03 sec)
    
    mysql> describe sub_category;
    +----------+--------------+------+-----+---------+-------+
    | Field    | Type         | Null | Key | Default | Extra |
    +----------+--------------+------+-----+---------+-------+
    | sid      | int(11)      |      | PRI | 0       |       |
    | pid      | int(11)      |      |     | 0       |       |
    | subphoto | varchar(60)  | YES  |     | NULL    |       |
    | subtitle | varchar(60)  | YES  |     | NULL    |       |
    | suburl   | varchar(255) |      |     |         |       |
    +----------+--------------+------+-----+---------+-------+
    5 rows in set (0.00 sec)
    
    mysql> describe sub_category_links;
    +------------+--------------+------+-----+---------+-------+
    | Field      | Type         | Null | Key | Default | Extra |
    +------------+--------------+------+-----+---------+-------+
    | sid        | int(11)      |      | PRI | 0       |       |
    | link_url   | varchar(255) |      | PRI |         |       |
    | link_title | varchar(60)  | YES  |     | NULL    |       |
    +------------+--------------+------+-----+---------+-------+

  2. #2
    SitePoint Guru asterix's Avatar
    Join Date
    Jun 2003
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
       select suburl, link_url, subtitle
       from sub_category as S, sub_category_links as L
       where L.sid = S.sid
    Is just one of at least 3 ways I can think of doing it


Bookmarks

Posting Permissions

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