我是Stack Overflow和ASP的新手,但是這個網站已經幫我多次了!我對ASP和VBS非常不熟悉,但對PHP更加熟悉,所以如果有針對我的問題的PHP解決方案,那也可以。按日期排序,但類似的字段組
有一點背景 - 我的訪問數據庫有兩個表(與此查詢有關),其中一個名爲SignUpLog
,另一個是Notes
。 SignUpLog.FirstNoteAddr
字段對應於另一個表中的Notes.NoteKey
字段。
我已經成功地顯示了數據庫中的所有條目,但是我想要將特定患者的所有條目組合在一行中,同時仍按日期排序(最新的位於頂部)。
這裏是我的代碼:
Set DataConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
DataConn.Open "DBQ=" & Server.Mappath("/path/to/mydb") & ";Driver={Microsoft Access Driver (*.mdb)};Uid=user;Pwd=pass;"
Set rsDsp = DataConn.Execute("SELECT SignUpLog.PatientFileNumber, SignUpLog.ArrivalDateTime, Notes.Note, SignUpLog.Called, SignUpLog.DrName FROM SignUpLog, Notes WHERE (((Notes.NoteKey)=[SignUpLog].[FirstNoteAddr])) ORDER BY SignUpLog.ArrivalDateTime DESC;")
If rsDsp.EOF Then
Response.Write "Sorry, no entries in the database!"
Else
%>
<div align="center"><center>
<table BORDER="0" width="700">
<tr>
<th width="105">Name</th>
<th width="105">Arrival Time</th>
<th width="105">Doctor</th>
<th width="105">Notes</th>
</tr>
<%
While Not rsDsp.EOF
x = x + 1
If x = 1 Then
Response.Write "<TR><TD>" & rsDsp.Fields.Item("PatientFileNumber").Value & "</TD>"
Response.Write "<TD>" & rsDsp("ArrivalDateTime").Value & "</TD>"
Response.Write "<TD>" & rsDsp("DrName").Value & "</TD>"
Response.Write "<TD>" & rsDsp("Note").Value & "</TD></TR>"
Else
Response.Write "<TR><TD BGCOLOR=E4E4E4>" & rsDsp.Fields.Item("PatientFileNumber").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("ArrivalDateTime").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("DrName").Value & "</TD>"
Response.Write "<TD BGCOLOR=E4E4E4>" & rsDsp("Note").Value & "</TD></TR>"
x = 0
End If
rsDsp.MoveNext
Wend
Response.Write "</TABLE>"
DataConn.Close
End If
%>
</table>
</center></div>
這給我類似這樣的輸出:
Patient A | 9/18/2012 12:56:21 PM | Appt | Note1
Patient A | 9/18/2012 12:56:21 PM | Appt | Note2
Patient A | 9/18/2012 12:56:21 PM | Appt | Note3
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note1
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note2
什麼,我想是這樣的:
Patient A | 9/18/2012 12:56:21 PM | Appt | Note1, Note2, Note3
Patient B | 9/18/2012 1:56:21 PM | WalkIn | Note1, Note2
我我試圖玩Group By
並保持因爲我沒有試圖做任何數學的事情,這讓我很困惑。就像我說的,我是一個完整的ASP noob,我不是一個程序員。
這是有點過頭了。對於我想要做的事似乎有點複雜。也許你可以詳細說明一下,請記住我在這個大聲笑noobot –