Results 1 to 2 of 2
  1. #1
    am17mu is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Default <tr><td> arrangement in a method

    Hi EveryOne,

    I have this code, which is used to access, a table from the database (postgresql) and is used to display 5 attributes, with all data, in the following format

    JudgeId Name Designation Address Active Status
    1 *** *** *** ***
    2 *** *** *** ***
    .
    .
    . as follows

    the code i have writen is as follows

    Java Code:
    String Qry= "SELECT \"JUDGEID\",\"NAME\",\"DESIGNATION\",\"ADDRESS\",\"ACTIVE_STATUS\" FROM \"Tax\".\"JUDGES\"";
                rset= stmt.executeQuery(Qry);
                while(rset.next()){
                    list.add(rset.getString(1));
                    list.add(rset.getString(2));
                    list.add(rset.getString(3));
                    list.add(rset.getString(4));
                    list.add(rset.getString(5));
                }
              
       /*this for loop, works fine for 2 elements,but for 5 elements, as above
                it does not display properly. */
                 for(int i=0;i<list.size();i++){
                    if(i==0 || i%2==0){
                        list.set(i,"<tr><td align='center'>"+list.get(i)+"</td>");
                    }else{
                        list.set(i,"<td align='center'>"+list.get(i)+"</td></tr>");
                    }
            }
    *******************************************
    I know, the problem lies within the if code, something with the <tr><td>
    But can't seem to make it work
    Please help guys
    Thanks in advance
    am17mu

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    I think you're right. The problem is in your if condition.

    Java Code:
    for(int i=0;i<list.size();i++){
                    if(i==0 || i%2==0){
                        list.set(i,"<tr><td align='center'>"+list.get(i)+"</td>");
                    }else{
                        list.set(i,"<td align='center'>"+list.get(i)+"</td></tr>");
                    }
            }

    I'm not sure why you open your <tr> element when the if is true and close if when it is not.

    I think there are some better ways to accomplish what you are going for but it's hard to tell without seeing more code.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 05:12 PM
  2. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  3. Method Help
    By pringle in forum New To Java
    Replies: 4
    Last Post: 04-16-2008, 01:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •