SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Joining Query

  1. #1
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Joining Query

    I am having difficulty figuring out the join query statement for this.

    Name of Table1: vpt_table_partlist
    Field for Table1: Partlist_ID | Part_No | Part_Desc

    Name of Table2: vpt_table_name
    Field for Table2: ID | Partlist_ID | Parent_ID

    I am receving Part_No by $_GET['part_no'];

    So how can I join the query to get ID (from Table2) for the Part_No (in Table1)? Both table have Partlist_ID as common field.

    Hope this makes sense, Help me understand if my logic is correct or this is not possible.

    Thanks.
    Last edited by jjdave; Apr 3, 2007 at 08:08.

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I understand, you get Part_No and you want Partlist_ID or Parent_ID ? also the tables are related by the Partlist_ID field, not Parent_ID

    Clear up the question and we'll advise after because right now with the ambiguous question, you don't need a join to get the ID if it's the Partlist_ID you want that is associated with the Part_No.
    David

  3. #3
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Joining Query...

    Quote Originally Posted by ClickHeRe View Post
    Clear up the question and we'll advise after because right now with the ambiguous question
    I have updated the beginning of Thread, there was an error from my part.

    Thanks.
    Last edited by jjdave; Apr 3, 2007 at 08:11. Reason: Reposted with Clerification

  4. #4
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might help:
    Code:
    SELECT name.ID FROM vpt_table_name as name JOIN vpt_table_partlist as partlist ON partlist.Partlist_ID = name.PartList_ID WHERE partlist.Part_No = '1'
    But change the where clause to an escaped $_GET['Part_No']
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  5. #5
    SitePoint Addict
    Join Date
    Jul 2005
    Posts
    215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WLHosting View Post
    But change the where clause to an escaped $_GET['Part_No']
    What does it mean (escaped $_GET['Part_No])???

  6. #6
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using something like mysql_escape_string or mysql_real_escape_string:
    http://us2.php.net/mysql_escape_string
    http://us2.php.net/mysql_real_escape_string

    This just makes sure that no extra quotes could mess up your $_GET['Part_No'].
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers


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
  •