Click to See Complete Forum and Search --> : list pages?


ba02000
03-12-2006, 10:36 AM
Hi guys,

I want to build two jsp pages to display user informations from database, as follow:
The first page contains many check boxes each checkbox is for user attribute (a checkbox for user age, another one for user address, another one for user phone, etc.) and the other page displays the checked attributes from the first page. The second page gets the information from MySQL 5.0 database.

So if user checked age, address, phone, and email boxes the second page will display the previous attributes as a list for all users, and if user checked phone and email the second page will display phone and email for all users, and so on.

I just need your thoughts and opinions and if it is possible some links for forums or sites discuss what I want to do, I don't know what's the process name so I described it as best as I could. :o :D

Regards,

Khalid Ali
03-12-2006, 10:58 AM
Well eseentially what you need is as follows.
each checkbox should be a field(column) in the database
such as...
name,phone,email etc
Now when user selects any of those attributes, and submits the request, then you will need to retrieve any of the checkboxes that were selected and create a query...eg
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String email = request.getParameter("email");

now you want to make sure to put a logic here that you always check for all attributes and only those will be considered who are actually set on the page. The values which are not checked in the html page will be recieved on the serverside as a null value.
Now to create a columnName string you will need to create a logic as follows.

String columnName="";
if(name==null){//if null then don't add columnName
columnName+="name");
}

if(phone ==null){//if null then don't add columnName
columnName+=",";
columnName+="phone");
}

if(email ==null){//if null then don't add columnName
columnName+=",";
columnName+="email");
}

//create sql query with the user selected attributes.
[code]
"SELECT +columnNames+ " FROM tableName;";


Then get the results back in an object such as UserData (or any suitable name), and then using java.util.Lists print each object and its properties in the page..

Hope this helps...good luck

ba02000
03-12-2006, 11:57 AM
Thank you man,,
But I have many attributes of the user and these attributes are distributed to many tables (for ex. email and phone in tbl_contact, P.O.Box ,street name, city and country in tbl_address, and so on)
So do I follow the same logic you gave to me or there is a better one for large number of attributes.

Thank you again, you put me on the right way

Regards,
Bashar

Khalid Ali
03-12-2006, 01:01 PM
the logic prety much can stay the same, only you will have to determine what query to write based upon which parameter(attriobutes) are selected by user. Say if email is in a different table then query will be changed drastically, now you will have to write a query that will link two tables....etc