CodeAve.com CodeAve.com - ASP - Database Table Display
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Displaying Output Grouped By Category
SQL will help to organize your db output, but in order to display data subsets by category you will to keep track of when a previous category ends and a new one begins. Utilizing a db created of links for products into Amazon.com we can subset db records between the three categories in the db (Toys, Books and Software). Select * from amazon order by category asc will select all the observations in the db and order then by category in ascending (alphabetic) order. You will now have observations output in blocks by category, but a few things are needed in order to recognize when a new category has started from the previous. if category <> last_category then checks the record set value for the current category against the last_category value which in the first iteration is null and in subsequent iterations contains the record set value just prior to the move next command that moves to the next observation. If the next observation has a different value then the category is outputted and all the observation within that category are displayed.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

<%
accessdb="category"
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)

set rs = server.createobject("ADODB.Recordset")
' The output data must be ordered by the element
' that you want to use as your category
sql = "select * from amazon order by category asc"
rs.Open sql, cn

rs.movefirst
do while not rs.eof

category=rs("category")
' if the category is not equal to the previous category
' then output the category
' (On the first interation last_category will be null
' and cause the first category to output)
if category <> last_category then
%>

<br><br>
<b>
<%= category %>
</b>
<%
end if
%>

<br>
<a href="<%= rs("link") %>">
<%= rs("title") %></a>
<%
' Places the current category value in the last_category field
' After each iteration last_category will be filled with the value
' of the category from the previous observation
last_category=category
rs.MoveNext
loop
%>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3