Fork me on GitHub

DBUtil and LIMIT  Bottom

  • I have a problem getting info from DB, I guess it is because its quite a big array I'm trying to get. I'm new to DBUtil, so I'm having some difficulties with LIMIT. I have looked through the developer docs, but I'm still getting the same error. The error is that I get the option to download the index file. I have tried limiting to very few, but still no luck, I'm gonna try pagination too, but well... STUCK...

    Jeanie

    This is my code:

    Code

    function Writer_stories_view()
    {
        $startnum = pnVarCleanFromInput('startnum');

        if (!pnSecAuthAction(0, 'Writer::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }
        $pnRender = pnRender::getInstance('Writer', false);
        $pnRender->caching = false;
        $itemsperpage = pnModGetVar('Writer', 'itemsperpage');
       $table = "stories";
        $storyitems = pnModAPIFunc('Writer', 'objects', 'view',
                            array('table' => $table));

    //    foreach ($storyitems as $key => $storyitem) {
    //        if (pnSecAuthAction(0, 'Writer::', "$storyitem[title]::$storyitem[storyid]", ACCESS_READ)) {
    //            $options = array();
    //            if (pnSecAuthAction(0, 'Writer::', "$storyitem[title]::$storyitem[storyid]", ACCESS_EDIT)) {
    //                $options[] = array('url'   => pnModURL('Writer', 'stories', 'modify', array('storyid' => $storyitem['storyid'])),
    //                                   'title' => _EDIT);
    //                if (pnSecAuthAction(0, 'Writer::', "$storyitem[title]::$storyitem[storyid]", ACCESS_DELETE)) {
    //                    $options[] = array('url'   => pnModURL('Writer', 'stories', 'delete', array('storyid' => $storyitem['storyid'])),
    //                                       'title' => _DELETE);
    //                }
    //            }
    //            $storyitems[$key]['options'] = $options;
    //        }
    //    }
        $pnRender->assign('storyitems', $storyitems);
        return $pnRender->fetch('writer_stories_view.htm');
    }


    and in the objectsAPi

    Code

    function Writer_objectsapi_view($args){
        $pntable = pnDBGetTables();
        extract($args);

        if ($args['column'] == null){
            $where = '';
        } else {
            $limitOffset = -1;
            $limitNumRows = 3;
            $usercolumn = $pntable[$args['column']];
            $selected = $args['where'];
            $column = $args['column'];
            $argument = $args['argument'];
            $where = "$usercolumn = $argument";
        }
        $items = DBUtil::selectObjectArray($args['table'],  $where, $args['orderby'], $limitOffset, $limitNumRows);
        return $items;
        }
  • Try removing

    Code

    extract($args);

    in Writer_objectsapi_view icon_smile

    --
    Guite | ModuleStudio
  • Thanks for reply!

    I'm still getting the "download this file dialogue" though :(

    Jeanie
  • To me
    it doesn't makes sense to call this:

    Code

    $storyitems = pnModAPIFunc('Writer', 'objects', 'view',
                            array('table' => $table));

    The idea of that apifunc is to provide some elements of that table, but there are many issues with the variables being used (talking about E_ALL errors)

    $limitOffset and $limitNumRows has no default values and $args are not properly checked if they are set or not, so, i guess that a better apifunc would be:

    Code

    function Writer_objectsapi_view($args) {
        $pntable = pnDBGetTables();
        // validates the passed table
        if (!isset($args['table']) || (isset($args['table']) && !isset($pntable[$args['table']]))) {
            return false;
        }
        // default values
        $startnum = isset($args['startnum']) ? $args['startnum'] : 1;
        $numitems = isset($args['numitems']) ? $args['numitems'] : pnModGetVar('Writer', 'itemsperpage', 10);
        $orderby  = isset($args['orderby']) ? $args['orderby'] : '';

        // build the where if needed
        $where = '';
        if (isset($args['column']) && !empty($args['column']) && isset($args['argument']) && !empty($args['argument'])) {
            $columns = $pntable[$args['table']];

            // checks that the specified column exists
            if (isset($columns[$args['column']])) {
                $usercolumn = $columns[$args['column']];
                $where = "$usercolumn = $args[argument]";
            }
        }

        return DBUtil::selectObjectArray($args['table'], $where, $orderby, $startnum, $numitems);
    }
    following the conventions of modules like News, Pages, etc.

    BTW, $args['where'] doesn't makes sense to me in that apifunc.
    only if you want to complete a previous where clause...

    Greetings and hope that the new apifunc work ok icon_wink
    be care with the var defaults, etc.

    --
    - Mateo T. -
    Mis principios... son mis fines
  • Thank you so much! It works perfectly now.

    *happy*
    Jeanie
  • 0 users

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