Recordset | data | database | Display a column display of database recordsets
/**
@ Author: Ci Qin Qiang
@Email: cqq1978@Gmail.com
*/
When you extract records from a database in ASP, PHP, or other languages, we are all in one line
Display, a single line of records, just like the following:
Name Sex Age origin
Ci Qin Qiang men 26 Rongcheng, Shandong Province
Li Yu Male 26 Beijing Fangzhuang
Sometimes, however, we also need to show that there are multiple records in each row, especially when the categories are displayed, such as:
Chemical industry textile industry clothing shoes and hats
Electronic information manufacturing Agriculture and forestry
Aquatic
A total of three columns displaying 3 messages per line.
I have seen some of my friends write programs, some of which are not very good, the following ASP as an example to illustrate:
One, the general wording
strSQL = "SELECT name from Category"
Set objRS = objConn.Execute (strSQL)
While Not objrs.eof
' The first column of each row
Response.Write objRS (0) & ""
Objrs.movenext
' Second column
Response.Write objRS (0) & ""
Objrs.movenext
' third column
Response.Write objRS (0) & ""
Objrs.movenext
' Back up one line
Response.Write "<br>"
Wend
Second, the improvement of the wording
Icolumn = 3 ' Show 3 columns per line
I=1 ' A scrolling mark, plus 1 each time
strSQL = "SELECT name from Category"
Set objRS = objConn.Execute (strSQL)
While Not objrs.eof
Response.Write objRS (0) & ""
Objrs.movenext
If I Mod icolumn=0 Then ' when three records are output, the line wraps
Response.Write "<br>"
End If
i = i + 1
Wend
Presumably we've all seen it, and we just have to judge in the loop,
If 3 records are exported, a newline character is printed and a single line of output is restarted.
Here we use the remainder operation Mod.