Column display of database recordset

Source: Internet
Author: User
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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.