Something people ask for a lot is code to turn data like examples listed below. Find enclosed group.asp while demonstrates a few ways to do this. It shows the raw data, groups it as plain text, in a table and in an unordered list. Raw Data
Parent 1 Child 1 Parent 1 Child 2 Parent 1 Child 3 Parent 2 Child 1 Parent 2 Child 2 Parent 2 Child 3 Parent 3 Child 1 Parent 3 Child 2 Parent 3 Child 3
Into
Parent 1 Child 1 Child 2 Child 3 Parent 2 Child 1 Child 2 Child 3 Parent 3 Child 1 Child 2 Child 3 Here is the code <!-- Author: Adrian Forbes --> <h1>Raw Data</h1> <% set objRS = createobject("ADODB.Recordset") objRS.Open "select Parents.ID, Parents.strParent, Children.strChild from Parents join Children on Children.intParent = Parents.ID ORDER BY Parents.ID", "dsn=TestDB;uid=sa;pwd=;"
while not objRS.EOF Response.Write objRS("strParent") & " " & objRS("strChild") & "<br>" & vbCRLF objRS.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %>
<h1>Plain text</h1> <% set objRS = createobject("ADODB.Recordset") objRS.Open "select Parents.ID, Parents.strParent, Children.strChild from Parents join Children on Children.intParent = Parents.ID ORDER BY Parents.ID", "dsn=TestDB;uid=sa;pwd=;"
sPrevParent = "" sParent = "" while not objRS.EOF sPrevParent = sParent sParent = objRS("strParent") if strcomp(sPrevParent, sParent) <> 0 then Response.Write "<p><b>" & sParent & "</b></p>" & vbCRLF end if Response.Write objRS("strChild") & "<br>" & vbCRLF objRS.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %>
<h1>Table</h1> <table border=0> <% set objRS = createobject("ADODB.Recordset") objRS.Open "select Parents.ID, Parents.strParent, Children.strChild from Parents join Children on Children.intParent = Parents.ID ORDER BY Parents.ID", "dsn=TestDB;uid=sa;pwd=;"
sPrevParent = "" sParent = "" while not objRS.EOF sPrevParent = sParent sParent = objRS("strParent") Response.Write "<tr>" if strcomp(sPrevParent, sParent) <> 0 then Response.Write "<td>" & sParent & "</td>" & vbCRLF else Response.Write "<td> </td>" & vbCRLF end if Response.Write "<td>" & objRS("strChild") & "</td></tr>" & vbCRLF objRS.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %> </table>
<h1>Unordered list</h1> <ul> <% set objRS = createobject("ADODB.Recordset") objRS.Open "select Parents.ID, Parents.strParent, Children.strChild from Parents join Children on Children.intParent = Parents.ID ORDER BY Parents.ID", "dsn=TestDB;uid=sa;pwd=;"
sPrevParent = "" sParent = "" bFirst = true while not objRS.EOF sPrevParent = sParent sParent = objRS("strParent") if strcomp(sPrevParent, sParent) <> 0 then if not bFirst then Response.Write "</ul>" & vbCRLF end if bFirst = false Response.Write "<li>" & sParent & vbCRLF & "<ul>" & vbCRLF end if Response.Write "<li>" & objRS("strChild") & vbCRLF objRS.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %> </ul> </ul> </table>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Database Code Articles More By aspfree developerWorks - FREE Tools! | Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
| | | | In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
| | | | Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
| | | | Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |