How To fetch a data from the table?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irfanmodan
    New Member
    • Jan 2011
    • 20

    #1

    How To fetch a data from the table?

    Hello everyone, I need Help...
    table name=test
    Code:
    Nid(PK)|    DID   | Parentid
    1      |    2,3   |    2
    2      |    4,5,6 |    3 
    3      |    NULL  |   5
    How to fetch parent id thru did=5 or did=6 in php.... please reply me asap...
    its urgent

    Thanks In Advance
    Last edited by Dormilich; Jan 20 '11, 01:47 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    just to make clear, in your example the Parentid would be 3?

    Comment

    • irfanmodan
      New Member
      • Jan 2011
      • 20

      #3
      ya...parent id is 3..
      in this table did and parent id both are documentid from other table which is pk of that table..
      means
      other table like document
      documentid
      1
      2
      3
      4
      5 etc

      i want to create sub menu so i used
      nid(pk) did and parentid
      table name like navigation

      Nid(PK)| DID | Parentid
      1 | 1,7 | 2
      2 | 4,5,6 | 3
      3 | NULL | 5

      i used below query ...
      SELECT did,parentid FROM navigation where did like '%5%'

      here problem is two raw are fetch...but i want only one row which is documentid=4 or 5 or 6....please help me what can i do...
      thanks in advance

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        the easiest way to limit the result is to LIMIT.
        Code:
        SELECT did,parentid FROM navigation WHERE did LIKE '%5%' LIMIT 1
        although I don’t see where 2 rows should come from in your shown table.

        Comment

        Working...