Configurable max in select statement

Hi everybody,

can someone tell me how to set the max property of a select to the value of a column? E.g.:

select {
orderBy = tstamp DESC
languageField = pages.sys_language_uid
max = tt_content.Columnname

Thx.

Hi Salvatore!

If I understand you correctly, you are trying to build an SQL query that returns records and where the maximum number of records returned is specified by a column in the returned result. (Something like: SELECT * FROM tt_content LIMIT columnname.) That would not be possible in SQL because the select query will hypothetically return more than a single row, and that would make columnname ambiguous.

A way this might be made to work is if you already have the maximum number of records handy from a previous query. With TypoScript you could access a column in that record with stdWrap. There are quite a few approaches, but max.field = columnname is a common one. Another is if you’ve fed the information into the registry using LOAD_REGISTER: max.data = register:maxRecords.

Sorry if that looks a bit technical. Without more context, it’s hard to give a good example. If you tell me more about what you’re trying to do, I’ll be able to help you further.

Best wishes

Mathias

Hi Mathias,

thanx for helping.

Actually the Typoscript is rendering a certain content-element. The relevant code within is:

lib.recentlyCommentedPages = CONTENT
lib.recentlyCommentedPages {
	table = pages
	wrap  = |

	select {
		orderBy       	= content.xc_recently_commented_pages_comment_time DESC
		languageField 	= pages.sys_language_uid
		max           	= 15
    	join          	= tt_content content ON content.pid = pages.uid AND content.xc_recently_commented_pages_comment != '' AND content.xc_recently_commented_pages_comment_time <= CURRENT_TIMESTAMP() AND content.deleted = 0 AND content.hidden = 0 AND ( content.starttime = 0 OR content.starttime <= UNIX_TIMESTAMP()) AND ( content.endtime = 0 OR content.endtime >= UNIX_TIMESTAMP()) AND ###VALID### LIKE CONCAT( '%', content.fe_group,'%')

		markers {
			VALID.data = TSFE:fe_user|user|usergroup
		}...

“max =” needs to be mapped to a certain column of the currently rendered content-element, as you assumed correctly.

I tried to find a way to get the uid of the currently rendered content-element to assign it to max but I can’t find a way to retrieve that uid.

Hi Salvatore!

Depending on your setup, it could be as simple as max.field = columnname.

You can check this by enabling stdWrap’s debugData property with max.debugData = 1. The content of the internal data array should be output in the frontend. (Of course, this is only for development use. Don’t do this on a live site!)

Many TypoScript content objects, like CONTENT and RECORDS will set the internal data array, which is accessible from within properties supporting stdWrap, like the max property of a select. Then you can simply access it using stdWrap’s field property. debugData allows you to see what that data array is set to.

— Mathias

Hi Mathias!

max.field worked! Thanx a lot, also for the .debugData tip that is very helpful!

1 Like