Featured Posts

jQuery Expand/Collapse All Menu PluginjQuery Expand/Collapse All Menu Plugin Another take on an expand/collapse style navigation. For our requirements, the navigation was a template and needed to be n-levels deep to take into account any possible...

Readmore

jQuery Dynamic FormjQuery Dynamic Form Scenario: Building web forms can be tricky when a form calls for a variable number of fields. A real-world example might be a sports team with an n number of players. When...

Readmore

A PHP Pagination FunctionA PHP Pagination Function Here's a PHP function "getPaginationHtml()" that builds an item-pagination type HTML DIV based on parameters only, i.e. no database recordset needed. Note the user of a second...

Readmore

A PHP Calendar Class Based on Zend_DateA PHP Calendar Class Based on Zend_Date A recent project required an event calendar in both a mini and full sized format. The project was based on Zend Framework, a highly scalable and feature-rich PHP MVC framework....

Readmore

Analyzing the Impact of Web Page Textual Data Representation on the  Accuracy of Selected Supervised Learning ModelsAnalyzing the Impact of Web Page Textual Data Representation... We looked at the effectiveness of supervised learning models in solving the real-world problem of web page classification. We attempted to maximize the performance of...

Readmore

Arietis Software Innovations Rss

A PHP Pagination Function

Posted on : 08-11-2009 | By : Derek | In : PHP, Pagination, Posts

Tags: ,

0

Here’s a PHP function “getPaginationHtml()” that builds an item-pagination type HTML DIV based on parameters only, i.e. no database recordset needed. Note the user of a second function that is used by the pagination function to build the URL parameters needed for the pagination links.

Visual example:

item_pagination_screen

 

How to call the getPaginationHtml() function:

//show the pagination html in an ordered list based on the listed arguments
echo getPaginationHtml(array('numRecords' => 12, 'numRecordsToShow' => 3, 'currPage' => 1, 'showPages'=>true));

 

HTML Output:


 

Functions:
1) getPaginationHtml()

/*
 * Get the pagination link HTML
 * @return String
 */
function getPaginationHtml ($args = array()) {

    $defaultArgs = array('numRecords'=> 1,
    					'numRecordsToShow'=>10,
                        'currPage'=>1,
                        'linkSeparator'=>'|',
                        'showPages'=>false,
                        'pageParamName'=>'page',
                        'firstClass'=>'pagination-first',
                        'prevClass'=>'pagination-first',
                        'nextClass'=>'pagination-next',
                        'lastClass'=>'pagination-last',
                        'pageClass'=>'pagination-page-link',
                        'separatorClass'=>'pagination-separator');
    $userArgs = array_merge ($defaultArgs, $args);
    foreach ($userArgs as $key=>$val) {
        ${$key} = $val;
    }

    //vars
    $links = array();
    $paramUrl = getParamUrl(array('exclude'=>'page')); //exclude the 'page' url param
    $totalPages = ceil($numRecords/$numRecordsToShow);

    //build  'num records' text
    $from = (($currPage-1)*$numRecordsToShow) + 1;
    $to = min(($from+$numRecordsToShow-1), $numRecords);
    $links[] = "
  • $from–$to of $numRecords records
  • "; //show page numbers if ($showPages) { for ($i=1; $i< = $totalPages; $i++ ) { ($i == $currPage) ? $selected = "$pageClass-selected" : $selected = ''; $links[] = "
  • $i"; } } //build 'first' link $links[] = "
  • First
  • "; //build 'prev' link $prev = max($currPage-1, 1); $links[] = "
  • < Prev
  • "; //build 'next' link $next = min($currPage+1,$totalPages); $links[] = "
  • Next >
  • "; //build 'last' link $links[] = "
  • Last
  • "; return implode("
  • $linkSeparator
  • ", $links); }

     

    2) getParamUrl()

    /*
     * Build the URL based on the current GET/POST parameters
     * excluding any unwanted parameters (comma separated if more than one).
     * i.e.: array('exclude'=>'page,sortname,sortorder');
     * @return String
     */
    function getParamUrl ($args = array()) {
        $defaultArgs = array('exclude'=> false);
        $userArgs = array_merge ($defaultArgs, $args);
        foreach ($userArgs as $key=>$val) {
            ${$key} = $val;
        }
        //check if GET or POST
        (isset($_GET)) ? $_params = $_GET : $_params = $_POST;
        //build the url string
        $paramUrl = array();
        foreach ($_params as $key=>$value) {
            $toExclude = explode(',', $exclude);
            if ($toExclude && !in_array($key, $toExclude)) {
                array_push($paramUrl, "$key=$value");
            }
        }
        return '?'.implode('&',$paramUrl);
    }
    VN:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)

    A PHP Calendar Class Based on Zend_Date

    Posted on : 26-05-2009 | By : Derek | In : PHP, Posts, Zend

    Tags: ,

    14

    A recent project required an event calendar in both a mini and full sized format. The project was based on Zend Framework, a highly scalable and feature-rich PHP MVC framework. The resulting Calendar class is admittedly quite basic, but I thought it might prove useful for other PHP/Zend coders who are trying to find a simple yet extensible Calendar solution for their own projects.

    Localization

    The benefit of using Zend_Date is that it relies on Zend_Locale for localization. To promote this, this custom Calendar class can be used to create a calendar in any language via the class constructor’s ‘locale’ parameter.

    Features

    • It can output HTML in the form of a table with the month, days of the week, and days visible.
    • It can generate the calendar HTML header alone, or the calendar HTML table body alone.
    • It can also be used to generate previous and next month links in the case you wanted to allow users to select the month themselves.
    • There is control over the table css, select box css , and select box form name via the html methods parameters
    • The class can also be used to generate Calendar data that you can access via more standard (get and set) methods to support your own unique Calendaring needs, i.e. without relying on HTML output.

    Demo

    Here is a link to a demo to get you started.

    Downloads

    1. Download the code here: [download id="4"]
    2. Comment below and let me know if it met your needs!

    Source/Contribute

    A View Helper version is being developed:
    Project source: zfcalendar project hosting

    VN:F [1.9.3_1094]
    Rating: 4.2/5 (3 votes cast)