Tip

A way for Web authors to sort as they see it on the Web

This tip shows you how to manipulate a string from a DbLookup to be displayed in a browser in a two (or more) column format and sorted counting from left to right, row by row (instead of from top to bottom, splitting the list in two columns).

This is useful when you want your author to decide the sort order of the items - for example if you have a startpage with news highlights in two columns and you want the first item at the top of the first column and the second item at the top of the second column and the third item at the second row of the first column and so on.

 Code: REM "This code makes a list of links to be displayed in a two column format counting items from left to the right and row by row."; REM "Linklist is generated by a lookup. The links are already HTML formated in the view"; view:="your view"; key:="your key"; list:=@DbLookup( "" : "NoCache" ; "" ; view ; key ; 4 ); REM "Some HTML that is reused later on"; tablestart:="<!-- Start contentstable --><TABLE width="100%" cellpadding=5 BORDER=0 CELLSPACING=0 >"; tableend:="</TABLE><!-- End contentstable -->"; dummy:="<IMG SRC="/icons/ecblank.gif" BORDER=0 HEIGHT=1 WIDTH=1 ALT="">"; REM "Number of elements and testing if number is odd or even"; listElements:=@Elements(list); odd:=@Modulo(listElements;2); REM "Linklist plus a dummy item if number is odd "; linklist:=list:@If(odd=1;dummy;""); REM "Generate strings that will be exploded into taglists. The ~ sign is used as separator"; REM " As this is a two column format, a table row start tag and end tag is needed every second item. The separator is used when exploding the string into a list of tags"; separator:="~"; repeatTimes:=@Round(listElements/2)); tagstring1:=@Repeat("<TR><TD>" + separator + "<TD>~"; repeatTimes ) tagstring2:=@Repeat("</TD>" + separator + "</TD></TR>~";repeatTimes) REM "The lists to be concenated with the linklist" REM "The first tag list will look like this: start <TR><TD> : <TD> : <TR><TD> : <TD> : ..."; REM "The second tag list will look like this: </TD> : </TD></TR> : </TD> : </TD></TR> : ..."; taglist1:=@Explode(tagstring1;separator); taglist2:=@Explode(tagstring2;separator); REM "The taglists and linklist put together"; REM "The output list will look like this: <TR><TD> link1 </TD> : <TD> link2 </TD></TR> : <TR><TD> link3 </TD> : <TD> link4 </TD></TR> : ..."; output:= tablestart + @Implode(taglist1 + linklist + taglist2;@NewLine) + tableend; @If(@IsError(templist);"";output)


This was first published in December 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.