# *** 怎样将显示的结果分成 4 列显示在页面中？ ***

tom00007 2006-02-09 04:54:31

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
......

1 8 15 22
2 9 16 23
3 10 17 24
4 11 18 25
5 12 19
6 13 20
7 14 21
...全文
197 点赞 收藏 20

20 条回复

Net8Java 2006-02-17

crazy2die 2006-02-16
<%
rs.last();
int count = rs.getRow();
int row = count/4;
rs.beforeFirst();
int value = 0;
while(rs.next()){
for(int i=1;i<=row;i++){
if((i+row*3)<=count){
out.println("<td>" + rs.getxxx(i) + "</td>" +
"<td>" + rs.getxxx(i+row) + "</td>" +
"<td>" + rs.getxxx(i+row*2) + "</td>" +
"<td>" + rs.getxxx(i+row*3) + "</td>");
}else if((i+row*3)>count&&(i+row*2<=count){
out.println("<td>" + rs.getxxx(i) + "</td>" +
"<td>" + rs.getxxx(i+row) + "</td>" +
"<td>" + rs.getxxx(i+row*2) + "</td>" +
"<td>" + " " + "</td>");
}else if((i+row*2>count)&&(i+row<=count)){
out.println("<td>" + rs.getxxx(i) + "</td>" +
"<td>" + rs.getxxx(i+row) + "</td>" +
"<td>" + " " + "</td>" +
"<td>" + " " + "</td>");
}else if(i+row>count&&i<=count){
out.println("<td>" + rs.getxxx(i) + "</td>" +
"<td>" + " " + "</td>" +
"<td>" + " " + "</td>" +
"<td>" + " " + "</td>");
}

}
%>

crazy2die 2006-02-16
<%
rs.last();
int count = rs.getRow();
int row = count/4;
for(int i=1;i<row;i++){
out.println("<td>" + rs.getxxx(i) + "</td>" +
"<td>" + rs.getxxx(i+row) + "</td>" +
"<td>" + rs.getxxx(i+row*2) + "</td>" +
"<td>" + rs.getxxx(i+row*3) + "</td>");
}
%>

fog628 2006-02-15
<%@ page contentType="text/html; charset=UTF-8" %>

<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%!
Connection conn;
Statement stmt;
%>
<%
String strSql = "select 1 id from dual ";
strSql += "union all select 2 from dual ";
strSql += "union all select 3 from dual ";
strSql += "union all select 4 from dual ";
strSql += "union all select 5 from dual ";
strSql += "union all select 6 from dual ";
strSql += "union all select 7 from dual ";
strSql += "union all select 8 from dual ";
strSql += "union all select 9 from dual ";
strSql += "union all select 10 from dual ";
strSql += "union all select 11 from dual ";
strSql += "union all select 12 from dual ";
strSql += "union all select 13 from dual ";
strSql += "union all select 14 from dual ";
strSql += "union all select 15 from dual ";
strSql += "union all select 16 from dual ";
strSql += "union all select 17 from dual ";
strSql += "union all select 18 from dual ";
strSql += "union all select 19 from dual ";
strSql += "union all select 20 from dual ";
strSql += "union all select 21 from dual ";
strSql += "union all select 22 from dual ";
strSql += "union all select 23 from dual ";
strSql += "union all select 24 from dual ";
strSql += "union all select 25 from dual ";

try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@localhost:1521:ORA";
//ORA为 SID
String user = "scott";
String password = "tiger";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(strSql);

int recordCount = 0; //record count
if(rs.last()){
recordCount = rs.getRow();
}
int[] arrData = new int[recordCount];
rs.beforeFirst();
int index = 0;
while(rs.next()){
arrData[index++] = rs.getInt(1);
}

//for(int i = 0; i < arrData.length; i++){
// out.println(arrData[i] + "<br>");
//}
int rowCount = recordCount / 4; //row count
if(recordCount % 4 != 0){
rowCount += 1;
}
//out.println(rowCount);
%>
<body>
<table border="1">
<%
for (int i = 0; i < rowCount; i++){
%>
<tr>
<td width="20"><% if(i < arrData.length) out.println(arrData[i]); %></td>
<td width="20"><% if(i + rowCount * 1 < arrData.length)
out.println(arrData[i + rowCount * 1]);
else
out.println(" "); %></td>
<td width="20"><% if(i + rowCount * 2 < arrData.length) out.println(arrData[i + rowCount * 2]);
else
out.println(" "); %></td>
<td width="20"><% if(i + rowCount * 3 < arrData.length) out.println(arrData[i + rowCount * 3]);
else
out.println(" "); %></td>
</tr>
<%
}
%>
</table>
</body>
<%
}catch(Exception e){
out.println(e);
}finally{
stmt.close();
conn.close();
}

%>
</html>

hanhongmin 2006-02-11

case1: a整除4-------自己捉摸去
case2: !a整除4
a除以4取整得b
b再加1，得c-----这是行数

——————————

wangx1949 2006-02-10

xunxm 2006-02-10

tom00007 2006-02-10

fog628 2006-02-10

fog628 2006-02-10

1.得到总记录数及行数：
if (reccount不是4的倍数) count=reccount增加到4的倍数
row = count / 4;

2.遍历ResultSet,把1,2,3.....25(假如是25)放到一个数组里arrData

3.生成表格：
for(int i = 0; i < row; i++){
%>
<tr>
<td>arrData[i]</td>
<td>arrData[i + 7 * 1]</td>
<td>arrData[i + 7 * 2]</td>
<td>arrData[i + 7 * 3]</td>
</tr>
<%
}

tom00007 2006-02-10

tom00007 2006-02-10

tom00007 2006-02-09
To: Samland(samland)

Samland 2006-02-09

reccount=记录总数
if (reccount不是4的倍数) count=reccount增加到4的倍数
row = count / 4;
<tr>
for (1 to 4) {
<td>
<div>
for (1 to row) 输出 rs.next()就内容
</div>
</td>
}
</tr>

tom00007 2006-02-09

<%
......

int recordNum = 0;

while( rs.next() )

recordNum++;
{
%>

<table border="1" width="100%">
<tr>

<td>
<table border="1" width="100%">
<tr>
<td>
<table border="1" width="100%">
<tr>
<td>
<table border="1" width="100%">
<%
rs.beforeFirst();

int n = (recordNum + 1)/4;
int i = 0;

while( i < n && rs.next() )
{
%>
<tr>
<td><% out.println(i+1);%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><u><font color="#FF0000">    </font></u></td>
</tr>
<%
i = i + 1;
}
%>
</table>
</td>

<td>
<table border="1" width="100%">
<%
while( i < ( ((recordNum + 1)/4)*2 ) && rs.next() )
{
%>
<tr>
<td><% out.println( (i++) + 1 ); %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><u><font color="#FF0000">    </font></u></td>
</tr>
<%
i = i + 1;
}
%>
</table>
</td>
</tr>
</table>
</td>

<td>
<table border="1" width="100%">
<tr>
<td>
<table border="1" width="100%">
<%

while( i < ( ((recordNum + 1)/4)*3 ) && rs.next() )
{
%>
<tr>
<td><% out.println(i+1);%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><u><font color="#FF0000">    </font></u></td>
</tr>
<%
i = i + 1;
}
%>
</table>
</td>

<td>
<table border="1" width="100%">
<%
while(rs.next())
{
%>
<tr>
<td><% out.println( (i++) + 1 ); %></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><u><font color="#FF0000">    </font></u></td>
</tr>
<%
}
%>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<%
}
rs.close();
%>
</tr>
</table>

tomuno 2006-02-09
you want what it is,and it is

tom00007 2006-02-09
To: tomuno(tomuno)

tomuno 2006-02-09
<%int i=1;%>
<%
for(int c=1;c<=7;c++){
out.println(i+" "+(i+7)+" "+(i+14)+" "+(i+21));
i++;
}
%>

tom00007 2006-02-09

Little_qd 2006-02-09

Web 开发

8.0w+

Java Web 开发

2006-02-09 04:54