[ic] Displaying number of rows in a table

Jerry interchange-users@icdevgroup.org
Tue Jul 1 09:21:01 2003

> I would like to access the number of items in a SQL table.  I haven't  
> had much luck getting at the results using SQL, and I'm wondering if  
> there's a simple way to access mv_return_fields after pointing a  
> [search] tag at one of the tables, or if it's easier to use the [query]  
> tag.
> 	I know I'm doing something wrong , but this is what I've 
> been trying:
> ------------------------------------------------------------------------ 
> -----
> [query
> 	sql="select count(*) as requestcount from www_mediarequest"
> 	type=list
> 	list=1
> 	st=db
> 	]
> 	[list]
> 		[sql-param requestcount]
> 	[/list]
> [/query]

To simply display the number of items in say... products table.

A little perl:

    [perl tables="products"]
       my $results = $Tag->query({
	   type => 'row_count',
	    sql => "select sku from products",
	return $results;

or even easier with the query tag:

 	sql="select sku from products"

Either of those should work. You can, of course, expand
the query a bit to count specific items matching and
given criteria.

Good Luck...