Fork me on GitHub

building select options from pnUserGetAll()??  Bottom

  • Hey all this should be a pretty simple one...well I hope it is, I am trying to get the username/email for every user on my system ( using pnUserGetAll to accomplish this ) and in return I want to strip out the username and email address for the users and input those as my options for a drop down select. I have figured out how to get the userdata from the API reference, but I am not sure how to get the loop for the options in the select to work so that I get the username listed with the value of the email address for given user. I hope this makes sense.


    Thanks
    -SUNADMN
  • You'd need to loop through the result set from the API to create an array suitable for the html_options plugin. This won't be exact but should get you started.

    PHP

    Code

    ..... pnRender instanstiation snipped.....
    $users = pnUserGetAll();
    $useritems = array();
    foreach ($users as $user) {
        $useritems[$user['email']) = $user['uname']'
    }
    $pnRender->assign('
    useremails', $useritems);
    return $pnRender-fetch('
    your _template.htm');


    template

    Code

    ..... rest of template snipped....
    <select name="email">
        <!--[html_options from=$useremails]-->
    </select>
    .... rest of template snipped....


    -Mark

    --
    Visit My homepage and Zikula themes.
  • Thanks Mark I knew their had to be a way of doing it.


    Thanks again
    -SUNADMN
  • Ok so I took a look at the code above and am trying to debug on my side now and for the life of me I am not sure where I messed up at here is my code thus far:

    Code

    function pnChange_admin_new()
    {
        if (!pnSecAuthAction(0, 'pnChange::', '::', ACCESS_ADD)) {
            return pnVarPrepHTMLDisplay(_MODULENOAUTH);
        }

        $pnRender =& new pnRender('pnChange');

        $pnRender->caching = false;

        if (pnUserLoggedIn()) {
           $name  = pnUserGetVar('uname');
           $email = pnUserGetVar('email');
        }

    $users     = pnUserGetAll();
    $useritems = array();

    foreach ($users as $user ) {
       $useritems($user['email']) = $user['uname']'
    }

        $pnRender->Assign('
    name', $name);
        $pnRender->Assign('
    email', $email);
        $pnRender->Assign('
    usermails', $useritems);

    //    return $pnRender->fetch('
    pnChange_admin_new.htm');
        return $pnRender->fetch('
    pnChange_test_java.htm');
    }


    And the error I produce is:

    Code

    Parse error: parse error, unexpected '=' in /var/www/noc/htdocs/modules/pnChange/pnadmin.php on line 32


    What have I done incorrectly here??


    Thanks
    -SUNADMN
  • As with any parse error you have a syntax error on (or before) that line.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • $useritems($user['email']) = $user['uname']'

    missing closing semicolon ^^^
  • Nope that's not it either I have chenged everything I can think of to make this work:

    Code

    foreach ($users as $user ) {
       $useritems($user['email']) = $user['uname']';
    }

    foreach ($users as $user ) {
       $useritems($user['
    email']) = $user['uname'];
    }

    foreach ($users as $user) {
        $useritems[$user['
    email']) = $user['uname']'
    }

    foreach ($users as $user) {
        $useritems[$user['email']) = $user['uname']';
    }


    none of the above work and still I can't hunt down the issue ( I have deleted the code that has the foreach loop and things run ok, I do not get errors ).

    I am lost as to what I could be missing... is it pointing me right in the face and I just dont see it???


    Thanks all
    -SUNADMN
  • You need to pay closer attention to the syntax your code ;) - check the number of square brackets on the left hand side of each of the array element assignments.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Code

    foreach ($users as $user) {
        $useritems[$user['email']] = $user['uname'];
    }


    That should do it. :)
  • Thanks Jedi that did infact clear up my error, still wondering why I didn't pick that up in my editor darn Zend... Anyway thanks for the obvious error hehehe...



    -SUNADMN
  • No worries. I do the same thing all the time. I'm getting better at "" and ; and (), but [] still mess me up. Just not used to analyzing them, I guess. :D
  • I do my editing in SciTE, and it makes this sort of thing easy to spot. You can tweak the syntax highlighting in a stylesheet to focus on the things that cause the most grief. For me it's deeply nested ().

This list is based on users active over the last 60 minutes.