SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up array and mysql join

    HI,
    I have two tables

    Catagory

    id name
    1 abc
    2 def
    3 bcd
    4 fff

    Subcatagory
    cid sid name
    1 1 subname1
    1 2 subname2
    2 3 subname3
    1 4 subname4

    Now I have a group array
    i.e
    Group1-> 1,3,4
    Group2->1,4
    ...

    Now as group is an array not a table , I cannot join to find out subcatagory id&name. Of course I can run select with where clause to find subcatagory.
    But , I was wondering is there a better way to show catname&subcatname
    by group ?

    Hope it is clear.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    No, I'm afraid it's not entirely clear. What do you mean by "group"? How do "groups" relate to the categories and subcategories?
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi , thanks for reply.

    $group1=array('1','3','4');
    $group2=array('1','4');

    so group1 will show

    cid subcatid name
    1 1 subname1
    1 2 subname2
    3 5 subname5
    4 4 subname4

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,907
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    In that case you could try something like

    PHP Code:
    $query='SELECT something FROM daTable WHERE id IN ('.implode(','$group1).')';
    // SELECT something FROM daTable WHERE id IN (1,3,4) 
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Member
    Join Date
    May 2005
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks a lot for reply.


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
  •