Fork me on GitHub

multiple sorting of information  Bottom

  • I want my users to be able to click on the heading of a certain colum in a table, and be able to sort the resultset by that column.

    I am a little confused as to how to do this.

    I use this on the htm template file (one example colum heading):

    Code

    <a href="<!--[pnmodurl modname="roqCamps" func="view" sort="number"]-->"><!--[pnml name="_ROQCAMPSNUMBER"]--></a>


    shere "sort" is the colum i want to sort by. i use this in the pnuser file in the view function:

    Code

    extract($args);
       
        $sort = pnVarCleanFromInput('sort');

     $camps = pnModAPIFunc('roqCamps',
                              'user',
                              'getall',
                              array('startnum' => $startnum,
                                    'numitems' => pnModGetVar('roqCamps',
                                                              'itemsperpage'),
                                    'sort'     => $sort));


    then in the pnuserapi file in the getall function i use this:

    Code

    extract($args);


        if (!isset($sort)) {
            $orderby = $roqCampscolumn[yr].' DESC, '.$roqCampscolumn[stDate].' ASC';
        }
        else {
            $orderby = $roqCampscolumn[yr].' DESC, '.$roqCampscolumn[$sort].' ASC';
        }

    $sql = "SELECT $roqCampscolumn[cid],
                       $roqCampscolumn[yr],
                       $roqCampscolumn[campname],
                       $roqCampscolumn[number],
                       $roqCampscolumn[stDate],
                       $roqCampscolumn[endDate],
                       $roqCampscolumn[grades],
                       $roqCampscolumn[price],
                       $roqCampscolumn[ebPrice],
                       $roqCampscolumn[desc],
                       $roqCampscolumn[albumNum],
                       DATE_FORMAT($roqCampscolumn[stDate], '%c/%D') AS formStDate
                FROM $roqCampstable
                ORDER BY "
    .$orderby;


    and everytime (i use die($SQL) to check the query) no matter what i do, it uses this version of the $orderby:

    Code

    $roqCampscolumn[yr].' DESC, '.$roqCampscolumn[stDate].' ASC';


    that tells me that i am not passing the argument $sort correctly. can anyone help me with this? am i even on the right track?
  • maybe you should check for empty instead isset

    --
    Bravecobra.com
  • Is this the correct way to send the argument $sort?
  • holy crap.....that worked!
  • I'm interested in seeing the resulting page, got a link?
  • Here ya go. As you will notice you can sort the list by any of the column headings. works pretty slick.

    http://www.horizoncenter.org/postNuke/index.php?module=roqCamps&func=view&meid=18

    Hope this helps.

    Billy
  • COOL, very nice work
    so what am I looking at in the code?
    roqcampscolumn is DB table and campname, number, stdate are fields?
    Oh wait this is an actual module? I have no clue how to create that. Can you fill me in? I'd like to use this.
  • Well, I found that building modules is much more difficult than i thought. I spent the good part of my Spring Break trying to figure it out. but I think i have it down pretty good now. but i am a beginner at this so I may not be completely accurate.

    I used the "example module" as a template. there is two ways to do it. You can use pnHTML or you can build a module based on pnRender. the "example module" is based on pnRender, where the "template module" is based on pnHTML. Since future packages of postNuke are going to be based on pnRender i decided to go with that.

    The example module is cluttered with comments. I would suggest takeing it very slowly and going step by step. thete is some good documentation (however not too in depth) to help with development.

    start with the pninit.php, pntables.php, and pnversion.php files and move along from there.

    the pnAdmin.php file is the interface file that connects pnAdminapi.php to the htm files in the pnTemplates folder.

    the most tedious, i thought, was that you have to go through and replace "Example" with your module title.

    I see you are a veteran here, and in fact i think you have helped me out a time or two, but the module development forum is very helpful you might browse through there.

    If you already know or understand this stuff, then i can explain a bit more where exactly this code goes in the module files.
  • where do I get this example module? Should probably look at that module developer's guide eh?
  • It's in the PostNuke distribution

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide

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