PHP Classes
Icontem

File: limit/limit.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Johan Barbier  >  SPL and Iterators  >  limit/limit.php  
File: limit/limit.php
Role: Example script
Content type: text/plain
Description: limit example
Class: SPL and Iterators
Implements several iterators using SPL
 

Contents

Class file image Download
<?php
/**
 * SQL access
 *
 */
DEFINE ('SQL_LOGIN',     'root');
DEFINE ('SQL_PWD',     'pwd');
DEFINE ('SQL_DB',     'dbname');
DEFINE ('SQL_HOST',     'localhost');

/**
 * Includes
 */
require_once 'package.oLimit.php';

/**
 * mysql testing
 */
/**
 * Connection
 */
$hCon mysql_connect (SQL_HOSTSQL_LOGINSQL_PWD);
mysql_select_db (SQL_DB$hCon);
/**
 * Query
 */
$sQuery = <<<sql
SELECT id FROM table
sql;
$rRes mysql_query ($sQuery$hCon);

try {
    
/**
     * Creating the mysqlLimit object using the factory, with arbitrary values (here, staring at offset 20, and retrieving the 10 next results)
     */
    
$limit LimitFactory::factory ('MYSQL'$rRes2010);
    
/**
     * while loop
     */
    
while ($limit -> valid()) {
        
/**
         * Displaying some values from mysqlLimit object
         */
        
echo '<p><strong>Internal Position : '$limit -> getInternalPos (), ' && Row Offset : ',$limit -> getExternalPos (),' => </strong></p>';
        
/**
         * Displaying current result array
         */
        
echo '<pre>'print_r ($limit -> current ()), '</pre>';
        
/**
         * Jumping to the next position
         */
        
$limit -> next ();
    }
catch (Exception $e) {
    echo 
$e -> getMessage (), ' on line '$e -> getLine ();
}

mysql_close ($hCon);

/**
 * array testing
 */
$aTab range (110005);

try {
    
$limit LimitFactory::factory ('ARRAY'$aTab15020);
    while (
$limit -> valid()) {
        echo 
$limit -> key (), ' => '$limit -> current (), '<br />';
        
$limit -> next ();
    }
catch (Exception $e) {
    echo 
$e -> getMessage (), ' on line '$e -> getLine ();
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products