1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Help pls - Arrays

Discussion in 'XenForo Development Discussions' started by Marc, May 22, 2011.

  1. Marc

    Marc Well-Known Member

    Hi Peeps,
    I am a very new coder in PHP and attempting a decent addon for xenforo. Reason I am doing so is I will learn a lot about both PHP and the framework as I go alone (at least thats the theory LOL). However I am struggling with something I need to do with some arrays.

    Here is the scenario. I have an array with values like so:

    PHP:
    array(array('user'=>1,'something_else'=>2,another_item=>26),
              array(
    'user'=>18,'something_else'=>4,another_item=>26),
              array(
    'user'=>5,'something_else'=>3,another_item=>26))
    I need to get the avatars for the users, so was going to use
    PHP:
    XenForo_Template_Helper_Core::getAvatarUrl($anArrayOfUsers,'m');
    So .... Here is my dilema. I cant figure firstly how to pass only a list of the users into the array from what I have above, and secondly how to then merge that into the original array as 'avatarURL'=>'blah'

    Really hope that makes sense. I could start looping through things etc etc, but Im sure there must be a better way of doing this.

    Any help would be greatly appreciated.
     
  2. ragtek

    ragtek Guest

    You can't pass an array with users to a method, which requires only 1 user;)
    You'll want to use foreach for this.

    PHP:
    $users = array(....);

    foreach (
    $users AS &$user{
    $user[$user['user_id]['avatar_url'] = XenForo_Template_Helper_Core::getAvatarUrl($user,'m')
    }
     
    Dan likes this.
  3. Marc

    Marc Well-Known Member

    So dont understand why it takes array as the input in that function... Tried to pass in just the userid but was given that message that says "Your an idiot" ... Least that was how I read the error message LOL.
     
  4. Marc

    Marc Well-Known Member

    LMFAO and now I get

    Undefined index: gender

    My brain hurts LMFAO .....
     
  5. Marc

    Marc Well-Known Member

    This is the code I have in my Model at the moment:

    PHP:
    <?php
    class dcXenMapMe_Model_MapMe extends XenForo_Model
    {

    public function 
    getMarkers()
    {
    $limit 5000;
    $userModel XenForo_Model::create('XenForo_Model_User');
            
    $data $this->_getDb()->fetchAll($this->limitQueryResults("
                SELECT member_id, 
                        lat,
                        lon
                FROM dc_MapMe_Markers
            "
    $limit0));    

            foreach (
    $data as $key => $values)
            {
                
    $i $key 1;
                
                
    $retval[$i] = array(
                    
                    
    'user'     => $values['member_id'],
                    
    'lat' => $values['lat'],
                    
    'lon' => $values['lon']
                );
            }
    foreach (
    $retval AS &$user)
    {
    $user['user']['avatar_url'] = XenForo_Template_Helper_Core::getAvatarUrl($user);
    }        

    return 
    $retval;
    }
    }
     

Share This Page