1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Array question...

Discussion in 'PHP' started by x0x, Sep 26, 2009.

  1. #1
    $icn = $DB->fetch("SELECT icon FROM $tab[fam] WHERE id='$id'", __FILE__, __LINE__);
    $icn2 = $DB->fetch("SELECT icon FROM $tab[fam] WHERE id='$pid'", __FILE__, __LINE__);


    Would it be possible to make that into one array instead of two queries?


    Like $icn['first'] and $icn['second'], would be the same query but 'first' => WHERE id='$id' and second => WHERE id='$pid'

    Just trying to make my code more compact...
     
    x0x, Sep 26, 2009 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Try:

    $icn = $DB->fetch("SELECT icon FROM $tab[fam] WHERE id='$id' OR id='$pid'", __FILE__, __LINE__);
    print_r($icn);
     
    ThePHPMaster, Sep 26, 2009 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    How do I know which one to pull? Let's say I want to pull the $id one?
     
    x0x, Sep 27, 2009 IP
  4. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #4
    do a var_dump($icn) and that will tell you what is what.

    it may say
    [0]->"blah"
    [1]->"blah1"

    Then $icn[0]=blah and $icn[1]=blah1

    it is harder to explain then I thought.
     
    dweebsonduty, Sep 27, 2009 IP
  5. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #5
    The first item in the array is the id and so on. MySQL returns columns the same order you specified them in the query.
     
    ThePHPMaster, Sep 28, 2009 IP