[ic] Look ahead at next value in a query/list?

Mike Heins mike at perusion.com
Mon Jul 7 13:36:02 EDT 2003

Quoting Interchange User (interchange at framework.cx):
> Hi all,
> Is there a way to look ahead at values returned by a [query] to tell if 
> there is another record about to be returned in between the 
> [list][/list] tags?  For instance, I have the following code, which 
> returns a list of authors from a table.  I want to put the comma after 
> "[sql-param author]" only if there's another author in the list, but 
> not at the end.
> ------------------------------------------------------------
> 		  [query
> 			sql="select author FROM authors where article = '[item-code]' ORDER 
> BY authorship"
> 			type=list
> 			list=1
> 			st=db
> 		  ]
> 		  [list]
> 			[sql-param author],
> 		  [/list]
> 		  [/query]
> ------------------------------------------------------------
> Currently, I end up with something like
> "Johnson J, Nichols RJ, Koch C, Gray J, Will L, Ernst B,"
> and I'd like to not put the comma in if I'm at the end of my results 
> lists.

	[sql-change 1]
	[else], [/else][/sql-change 1][sql-param author]

I have sometimes done in catalog.cfg:

Variable COMMA_SEP_SQL [sql-change 999][condition]1[/condition][else], [/else][/sql-change 999]


	    __COMMA_SEP_SQL__[sql-param author]

This is a common-enough need so that it might make sense to overload
[item-alternate], something like [item-alternate except_last]. In fact,
it makes so much sense that I have done it and put it in CVS. If you
use the latest, you will want:

	[sql-param author][sql-alternate except_last], [/sql-alternate]

Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.513.523.7621      <mike at perusion.com>

I have a cop friend who thinks he ought be able to give a new ticket;
"too dumb for conditions".

More information about the interchange-users mailing list