|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I display query results the way I want 'em?
I have a junction table which lists names in the first column and skills in the second column e.g.:
Name | Skill Name 1 | Skill 1 Name 1 | Skill 2 Name 1 | Skill 5 Name 2 | Skill 1 Name 2 | Skill 4 Name 3 | Skill 3 Name 3 | Skill 6 I want to display results on a webpage in the following format: Name 1: Skill 1, Skill 2, Skill 5 Name 2: Skill 1, Skill 4 Name 3: Skill 3, Skill 6 I've been told I need to use GROUP BY, but this expects an arthmetic operator or aggregate function like SUM. However, the data type is Text. How do I get what I need? |
|
#2
|
|||
|
|||
|
you could try something like this in ASP:
use an SQL query like Code:
SELECT * FROM table ORDER BY Name, Skill And display it like this: Code:
<table> <tr> <th>name</th><th>skills</th></tr><% Do While Not oResult.EOFsName = oResult.fields("Name").value %> <tr> <td><% = sName %> </td> <td> <% = oResult.fields("Skill").value oResult.MoveNext Do While Not oResult.EOF AND oResult.Fields("Name").value = sName %>Loop%> </table>, <% = oResult.fields("Skill").value oResult.MoveNextLoop %> </td></tr><% |
|
#3
|
|||
|
|||
|
How would you add another field?
Ive been trying to use what you did RvCNet but I modified it...
SQL: [CODE] <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th><span class="style1">Name</span></th> <th><span class="style1">Skills</span></th> </tr> <% priorName = "" Do While Not oRS.EOF sName = oRS.fields("BName").value work = oRS.fields("WorkType").value If sName <> priorName Then If priorName <> "" Then %> </td> </tr> <% End If %> <tr><td colspan="2"> </td></tr> <tr> <td valign="top" nowrap><span class="style1"><b><%= sName %></b><br> <%=oRS("BmailingAddress")%><br> <%=oRS("BCity")%>, <%=oRS("BState")%> <%=oRS("BZIP")%> <% if oRS("BWebSite") <> "" then %> <br> <b>Web Site:</b> <a href="http://<%=oRS("BWebSite")%>" target="_blank"><%=oRS("BWebSite")%></a><% end if %><br> <b>Phone:</b> <%=oRS("BPhone")%><br> <b>FAX:</b> <%=oRS("BFAX")%> </span></td> <td valign="top"><span class="style1"><%= work%> <% priorName = sName Else %> , <%=work%> <% End If oRS.MoveNext Loop %> </span> </td> </tr> </td> </tr> </table> CODE] My question now is how can I include another field very similar to the "WorkType"... Thanks... |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > How do I display query results the way I want 'em? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|