Click to See Complete Forum and Search --> : print multiple times..multiple rows...


abhit_kumar
01-17-2005, 08:56 AM
this below code is used for the retrieving values from the table.

The tables have several rows...


my prob.. is that when i retrieve more than one rows values..it print two times the same rows..

if i retrieve 3 rows values..it prints three times the same rows..

plz help me in my code....where is the prob...plz...

code:-

while(results.next()){



for (int j = 1; request.getParameter((j==1)?"Ac.code":("Ac.code_" +j)) != null; j++) {


out.println("<tr><td> <INPUT TYPE='TEXT' NAME='ac_code' size='12' value='" +request.getParameter((j==1)?"Ac.code":("Ac.code_" +j)) + "' readonly </td>");

out.println("<td><INPUT TYPE='TEXT' NAME='description' size='12' value='" + request.getParameter((j==1)?"description":("description_" +j))+ "' readonly </td>");

out.println("<td> <INPUT TYPE='TEXT' NAME='description' size='12' value='" + request.getParameter((j==1)?"description1":("description1_" +j)) + "' readonly </td>");
out.println("</tr> ");
}

konithomimo
01-17-2005, 06:03 PM
So you are saying that if you retrieve one row that it takes in 1 row, if you retrieve 2 rows, then it takes in 4 rows (both rows 2 times), if you retrieve 3 rows, then it takes in 9 rows (all 3 rows 3 times each), and so on ????

abhit_kumar
01-18-2005, 02:21 AM
yes..its like that...

whats the prob...plz tell me..

and make changes in my code....

Khalid Ali
01-18-2005, 07:50 AM
First of all I don't understand the reason or need for a for loop in side of while, it seems to me you are trying to write thing s over and over yourself. try removing the for loop and then use the following structure.
String param = request.getParameter(((j==1)?"Ac.code":"Ac.code_" +j));

Now to you problem presuming you had to use for loop,
if your query returns correct data then the problem has to be in the following condition in the for loop
for (int j = 1; request.getParameter((j==1)?"Ac.code""Ac.code_" +j)) != null; j++) {
particularly the bold part make it simple something like this

for (int j = 1; j<whatever value hrere; j++) {
String param = request.getParameter(((j==1)?"Ac.code":"Ac.code_" +j));
and then in your rest of the code use param instead of using the above construct over and over.