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! | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
| | | | Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
| | | | Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. 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!
| | | | As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br /> 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!
| | | | Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
| | | | Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |