A small problem (SQL+search+array+distinct)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Nørregaard

    A small problem (SQL+search+array+distinct)

    Hi,

    I have this Mysql db:

    id int(11) autoincremement prim. key
    parentid int(11)
    ... etc .. (fields for a discussion board)

    When parentid=0 then it is a new thread, otherwise it is a comment to
    the thread that has the id that is in parentid (hope you get the
    picture)
    when I want to search, I issue: select * from forum where (something)
    but then for instance I get:

    ID,parentid
    1,0
    3,0
    8,3
    9,3
    11,0

    How do I do so:

    a) all redundant PARENTID's are limited to one of each, and
    b) if a parentid is equal to any id, delete the parentid

    It all should end up in a list (arrray) of the ID's relevant.
    In the above instance it would be:
    1
    3
    8
    9
    11

    ParenIDs of 0 should be ignored.

    I am not very good at english, nor to explain myself, so please do not
    hesitate to ask further, or send me to another news group if
    appropriate.

    Sincerely,

    Adam
  • Adam Nørregaard

    #2
    Re: A small problem (SQL+search+arr ay+distinct)

    Nevermind, I use unique_array it worked great

    Comment

    • Rahul Anand

      #3
      Re: A small problem (SQL+search+arr ay+distinct)

      Adam Nørregaard <adam.noerregaa rd@e-mail.dk> wrote in message news:<a971vvo65 jvap9k6rp1k662f 3tk312ados@4ax. com>...[color=blue]
      > Nevermind, I use unique_array it worked great[/color]

      In PHP you can use *array_unique* function to remove duplicate values from an array.

      In of MySQL fetch loop, create an array of Ids by using syntax similar to:

      $id_array[] = $row['id'];
      $id_array[] = $row['parentid'];

      After completion remove duplicates:

      $id_array = array_unique($i d_array);

      Now $id_array will contain only unique ids

      -- Rahul

      Comment

      Working...