This page has the following setup.

Do you want to know how many spans have been generated by Chili?

Valid XHTML 1.0 Strict


Click on a language below to show / hide the code.

JavaScript 1


/*  
===============================================================================
Metaobjects is the metadata plugin on steroids
...............................................................................
                                               Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/metaobjects/
===============================================================================
*/ 
 
( function($) { 
$.metaobjects = function( options ) { 
 
    options = $.extend( { 
          context:  document 
        , clean:    true 
        , selector: 'object.metaobject' 
    }, options ); 
 
    function jsValue( value ) { 
        eval( 'value = ' + value + ";" ); 
        return value; 
    } 
 
    return $( options.selector, options.context ) 
    .each( function() { 
 
        var settings = { target: this.parentNode }; 
        $( '> param[@name=metaparam]', this ) 
        .each( function() {  
            $.extend( settings, jsValue( this.value ) ); 
        } ); 
 
        $( '> param', this ) 
        .not( '[@name=metaparam]' ) 
        .each( function() { 
            var name = this.name, value = jsValue( this.value ); 
            $( settings.target ) 
            .each( function() { 
                this[ name ] = value; 
            } ); 
        } ); 
 
        if( options.clean ) { 
            $( this ).remove(); 
        } 
    } ); 
}; 
} ) ( jQuery );

JavaScript 2




/*  
===============================================================================
Metaobjects is the metadata plugin on steroids
...............................................................................
                                               Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/metaobjects/
===============================================================================
*/ 
 
( function($) { 
$.metaobjects = function( options ) { 
 
    options = $.extend( { 
          context:  document 
        , clean:    true 
        , selector: 'object.metaobject' 
    }, options ); 
 
    function jsValue( value ) { 
        eval( 'value = ' + value + ";" ); 
        return value; 
    } 
 
    return $( options.selector, options.context ) 
    .each( function() { 
 
        var settings = { target: this.parentNode }; 
        $( '> param[@name=metaparam]', this ) 
        .each( function() {  
            $.extend( settings, jsValue( this.value ) ); 
        } ); 
 
        $( '> param', this ) 
        .not( '[@name=metaparam]' ) 
        .each( function() { 
            var name = this.name, value = jsValue( this.value ); 
            $( settings.target ) 
            .each( function() { 
                this[ name ] = value; 
            } ); 
        } ); 
 
        if( options.clean ) { 
            $( this ).remove(); 
        } 
    } ); 
}; 
} ) ( jQuery );

MySQL 1


/* 
extracted from "Advanced MySQL user variable techniques" 
(http://www.xaprb.com/blog/2006/12/15/advanced-mysql-user-variable-techniques/)
*/

CREATE TABLE fruits (
  `type` varchar(10) NOT NULL,
  variety varchar(20) NOT NULL,
  price decimal(5,2) NOT NULL default 0,
  PRIMARY KEY  (`type`,variety)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

insert into fruits(`type`, variety, price) values
('apple',  'gala',       2.79),
('apple',  'fuji',       0.24),
('apple',  'limbertwig', 2.87),
('orange', 'valencia',   3.59),
('orange', 'navel',      9.36),
('pear',   'bradford',   6.05),
('pear',   'bartlett',   2.14),
('cherry', 'bing',       2.55),
('cherry', 'chelan',     6.33);


set @num := 0, @type := '';

select `type`, variety, price, @num
from fruits
where 2 >= greatest(
   @num := if(@type = `type`, @num + 1, 1),
   least(0, length(@type := `type`)));

MySQL 2


/* 
extracted from "Advanced MySQL user variable techniques" 
(http://www.xaprb.com/blog/2006/12/15/advanced-mysql-user-variable-techniques/)
*/

CREATE TABLE fruits (
  `type` varchar(10) NOT NULL,
  variety varchar(20) NOT NULL,
  price decimal(5,2) NOT NULL default 0,
  PRIMARY KEY  (`type`,variety)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

insert into fruits(`type`, variety, price) values
('apple',  'gala',       2.79),
('apple',  'fuji',       0.24),
('apple',  'limbertwig', 2.87),
('orange', 'valencia',   3.59),
('orange', 'navel',      9.36),
('pear',   'bradford',   6.05),
('pear',   'bartlett',   2.14),
('cherry', 'bing',       2.55),
('cherry', 'chelan',     6.33);


set @num := 0, @type := '';

select `type`, variety, price, @num
from fruits
where 2 >= greatest(
   @num := if(@type = `type`, @num + 1, 1),
   least(0, length(@type := `type`)));