Fork me on GitHub

select menu data from item db  Bottom

  • for some reason i just can't get this to work. I am useing the template module to create a new module. I am attempting to fill a select menu on a form with the list of, (for this module) facilities.

    here is pnadmin.php

    Code

    $items = pnModAPIFunc('roqFacilities',
                              'user',
                              'getall');

        $pnRender->assign('items', $items);

        return $pnRender->fetch('roqFacilities_admin_new_wish.htm');


    this is the getall function from pnuserapi.php

    Code

    function roqFacilities_userapi_getall($args)
    {

        extract($args);

        // Optional arguments.
        if (!isset($startnum) || !is_numeric($startnum)) {
            $startnum = 1;
        }
        if (!isset($numitems) || !is_numeric($startnum)) {
            $numitems = -1;
        }

        $items = array();

        if (!pnSecAuthAction(0, 'roqFacilities::', '::', ACCESS_OVERVIEW)) {
            return $items;
        }

     pnDBGetTables()

        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $roqFacilitiestable = $pntable['roqFacilities'];
        $roqFacilitiescolumn = &$pntable['roqFacilities_column'];

        $sql = "SELECT $roqFacilitiescolumn[fid],
                       $roqFacilitiescolumn[facilname],
                       $roqFacilitiescolumn[consYear],
                  $roqFacilitiescolumn[pic],
                  $roqFacilitiescolumn[floorplan],
                  $roqFacilitiescolumn[maxOccup],
                  $roqFacilitiescolumn[season],
                  $roqFacilitiescolumn[primUse],
                  $roqFacilitiescolumn[extra_br],
                  $roqFacilitiescolumn[extra_sh],
                  $roqFacilitiescolumn[extra_ph],
                  $roqFacilitiescolumn[extra_k],
                  $roqFacilitiescolumn[extra_heat],
                  $roqFacilitiescolumn[extra_ac],
                  $roqFacilitiescolumn[location],
                  $roqFacilitiescolumn[albumNum]
                FROM $roqFacilitiestable
                ORDER BY $roqFacilitiescolumn[facilname]"
    ;

        $result = $dbconn->SelectLimit($sql, $numitems, $startnum-1);

        if ($dbconn->ErrorNo() != 0) {
            pnSessionSetVar('errormsg', _GETFAILED);
            return false;
        }


        for (; !$result->EOF; $result->MoveNext()) {
            list($fid, $facilname, $consYear) = $result->fields;
            if (pnSecAuthAction(0, 'roqFacilities::', "$facilname::$fid", ACCESS_OVERVIEW)) {
                $items[] = array('fid' => $fid,
                                 'facilname' => $facilname,
                                 'consYear' => $consYear,
                                  'pic' => $pic,
                                  'floorplan' => $floorplan,
                                  'maxOccup' => $maxOccup,
                                  'primUse' => $primUse,
                                  'season' => $season,
                                  'extra_br' => $extra_br,
                                  'extra_sh' => $extra_sh,
                                  'extra_k' => $extra_k,
                                  'extra_ph' => $extra_ph,
                                  'extra_ac' => $extra_ac,
                                  'extra_heat' => $extra_heat,
                                  'location' => $location,
                                  'albumNum' => $albumNum);
            }
        }

        $result->Close();

        return $items;
    }


    then this is the code i have for output in new_wish.htm

    Code

    <select id="roqFacilities_facility" name="wfid">
            <option selected>(facility)</option>
            <!--[section name="mysec1" loop=$items]-->
            <option value="<!--[$items[mysec1].fid|pnvarprephtmldisplay]-->"><!--[$items[mysec1].facilname|pnvarprephtmldisplay]--></option>
            <!--[/section]-->
            </select>


    it seems like it should work? but i am not getting any display except for "(facility)" which is already set.

    have i done something wrong?
  • i tried this:

    Code

    function roqFacilities_userapi_getall($args)
    {
    die('got here');


    and the process did not die. it continued then displayed new_wish.htm. it isn't calling userapi -> getall function for some reason.

    anyideas?
  • http://smarty.php.ne…on.html.options.php

    That's a really slick way to do option lists. You may need to make an extra array for it, depending on you you're doing stuff, but it's so slick that it's worth the effort.

    As for the not calling the user function, check for typos in your security checks or your API call.
  • i figured it out.

    you have to call the API function.

    ex.

    Code

    if (!pnModAPILoad('roqFacilities', 'user')) {
            return pnVarPrepHTMLDisplay(_LOADFAILED);
        }


    didn't know that. it is all loading properly now.

    as for the Smarty stuff. I have looked at it, but those manuals confuse me. When i get a better grasp on this stuff i will look into it more. I have to be able to understand their examples before i can understand the usage of it all.

    if you have any advice for a beginner and Smarty, i am all open ears. it seems as though that is the way to go. just gotta figure it out.
  • I hear you on the Smarty stuff. It takes a bit of getting used to.

    For the html_options thing, this is how you can use it.

    Make an array where the key is what you want the option value to be and where the value is what you want to display. For example, if you want to pick from a list of composers, this might be what your array looks like:

    $composers[bach] = Johan Sebastian Bach
    $composers[beethoven] = Ludwig von Beethoven
    $composers[williams] = John Williams

    In your template file (new_wish.htm in your case), the code would look something like this:

    Code

    <select name=favorite>
    <!--[html_options options=$composers selected=$favorite]-->
    </select>


    This would make a select list of the options array, where it would display the composers' full names, and the value that would be passed through the form would be what's in the key (bach, beethoven, or williams). The "selected=" bit selects whatever $favorite equals.

    Does that help at all? :)
  • does this work with more complex arrays....like being pulled from a DB?

    for instance i have a list of facilities -> $facil[] for each facility the array contains facilname, consYear, ect.

    also do you have to call this html_options plugin or is it already active? meaning can i just insert that exact code where needed after sending the appropriate array?
  • I'm not totally sure on the more complex arrays. I usually build a special array for the options, if I decide I need it.

    No guarantees this'll work 100% right the first time, but this is around how the pnadmi code should look

    Code

    $items = pnModAPIFunc('roqFacilities',
                              'user',
                              'getall');

       $facilities=array();
       foreach ($items as $item){
          $facilities[$item['fid']]=$item['facilname'];

       }

       $pnRender->assign('items', $items);

        $pnRender->assign('facilities', $facilities);

        return $pnRender->fetch('roqFacilities_admin_new_wish.htm');


    Yes, html_options is already active, so you don't have to call it. So you can use:

    Code

    <select id="roqFacilities_facility" name="wfid">
          <option selected>(facility)</option>
    <!--[html_options options=$facilities]-->
    </select>
  • 0 users

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