mysql SELECT * from table where (something that from a multidimentional array)

Discussion in 'PHP' started by fhelik, Feb 3, 2010.

  1. #1
    Hello forums

    is ti possible to query a mysql db but the WHERE belongs to a multidimentional array :


    $doors = Array
    (

    [links] => Array

    (

    [0] => Array

    (

    [text] => home

    )

    )

    )

    SELECT *FROM doors WHERE links = multidimentionalarray([text] => home) //

    as you see "text" is not right after "links" is after the element "0"

    so I can not use WHERE link.text because the 0

    any one? please :)
     
    fhelik, Feb 3, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure whether I understand the specifics of what you're asking, but you can burrow down into a multimensional array as follows:

    $sql = "select * from doors where links = '{$doors['links'][0]['text']}'";
    PHP:
     
    SmallPotatoes, Feb 3, 2010 IP
  3. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #3
    Or like that:

    $sql = "select * from doors where links = '".$doors['links'][0]['text']."'";
    PHP:
     
    Nei, Feb 3, 2010 IP
  4. fhelik

    fhelik Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    didn't work.

    ok if I run this query:

    SELECT links FROM table WHERE links != '' limit 2
    Code (markup):
    it gives me this:

    
    Array
    
    (
        [0] => Array
            (
                [links] => Array
                    (
                        [0] => Array
                            (
                                [text] => At street
                            )
                    )
            )
       [1] => Array
            (
                [links] => Array
                    (
                        [0] => Array
                            (
                                [text] => At Home
                            )
                    )
            )
    )
    
    Code (markup):
    But I want to do a query where it only gives me where the [text] = "At Home"

    I tried SELECT links FROM table WHERE links.text = 'At Home' limit 2 but it does not work

    Thank you for you time and any help with this
     
    fhelik, Feb 3, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I see. This is why posting more code helps - it was not clear what you were getting at.

    You must be using mysql_fetch_array(). If you are, then you will get a big array and have to work your way through it to get the values you need. You may wish to consider using mysql_fetch_assoc() and looping through the result set; it's more efficient for the server and there's less array gymnastics involved.

    The answer to your problem is easy but until you provide some more code and a description of the relevant database fields I cannot give you a concrete example.
     
    SmallPotatoes, Feb 3, 2010 IP
  6. fhelik

    fhelik Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You right, I was thinking to do all in one call and set a limit of 10 (this is just what I need)

    But using filters after the call is good too, I might have to use LIMIT 100, so I can get about 10 of what I need

    Thank you for your help, I added to your reputation.
     
    fhelik, Feb 4, 2010 IP