الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

JSP checkboxes state to and from Database

مغلق
بدأه mlotfi في 14 سبتمبر 2005 · 5 رد · 713 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Assalam alikom

I am trying to do this :

when a user login he will be presented with a form that has his skills (he already submited in this form), now he can change his skilles by checking or unchecking the checkboxes and when submit all are saved in a table in a database.

table : user_table (userID, username).

table : const_skills (skilID , value).

table : lookup_skills (lkupID, userID, skilID).

Please show me how to do it with JSP ?

Jazakom Allah khairan

#2

ما هي قاعدة البيانات التي تريد الاتصال بها و استخدامها

هذا الكود للاتصال مع mySQL مثلا

<%
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/jsp_test?user=root&password="; 
conn = DriverManager.getConnection(url);
statement = conn.createStatement();
هذه لكي تستخرج معلومات
ResultSet rs = statement.executeQuery("SELECT * FROM user_table");

او تستخدم
 هذه الطريقة من اجل التعديل كما طلبت
ResultSet rs = statement.executeUpdate("update const_skills set value= 56");

rs.close();
%>

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#3

السلام عليكم

شكرا اخي , ولكن لم اقصد هدا .

ماقصدته هو كيف عندما يستعمل المستخدم user login سيجد Form بكل skills مع checkbox لكل واحدة كما عدلها اخرمرة .

شكرا

#4

أعتقد أني فهمت قصد الأخ mlotfi فهو يقصد إعطاء القيم الأولية لأدوات الوسم Form في HTML (الـ CheckBox في حالته هنا) عند فتح المستخدم لصفحة سبق وأن وضع فيها إعداداته الشخصية وقد خزنت في قاعدة بيانات ما.

أليس كذلك؟؟

في الواقع أنا لا أعرف، وقد كنت أبحث عن إجابة لمثل هذا السؤال ولكن بشكله الأعم، أي إعطاء القيم الأولية لكافة أدوات الوسم Form مثل الـ TextBox وCheckBox وComboBox ....

#5

you are right brother

I am trying to do this :

when a user login he will be presented with a form that has his skills (he already submited in this form), now he can change his skilles by checking or unchecking the checkboxes and when submit all are saved in a table in a database.

table : user_table (userID, username).

table : const_skills (skilID , value).

table : lookup_skills (lkupID, userID, skilID).

My problem here is how to populate checked and unchecked checkboxes from database.

Problem 1 ::

Let say a user login for the first time (now we have his userID in a session), then he has a form that lists :

Please check your skills :

checkbox1 JSP

checkbox2 JAVA

checkbox3 HTML

the when he submit the form, only the skills with checkboxes he checked are inserted in the lookup_skills table.

My question here is how to construct the checkboxes in the form using the query : select * from const_skills ? in an other word :

<input type="checkbox" value= the first skilID from the query,

how to test the checked if it's false or true, />

<input type="checkbox" value= the 2nd skilID from the query,

how to test the checked if it's false or true, />

....

#6

استخدم Left join بين الجدول الذي يحتوي على الخبرات التي اختارها المستخدم و الجدول الذي يحتوي على كل الخبرات

في هذه الحالة نتيجة الاستعلام سترجع لك اسماء كل الخبرات بينما سترجع لك الأي دي الخاص بالخبرات التي اختارها المستخدم و القيمة نيول للخبرات التي لم يخترها المستخدم

select lookup_skills.lkupID , const_skills.skilID,const_skills.value from const_skills left join lookup_skills on (const_skills.skilID=lookup_skills and lookup_skills.userID=999);

999 هو رقم المستخدم مثلا

لتعرف ان كانت خبرة من الخبرات غير مختارة من طرف المستخدم تحقق ان قيمة الحقل lkupID لا تساوي 0 لان الجاي دي بي سي يرجع قيمة الصفر للقيمة نيول

while(rs.next())
{

int lkupID = rs.getInt("lkupID");
int skilID = rs.getInt("skilID");

string checked = lkupID == 0 ? "" : "checked";
%>
<input type=checkbox <%=checked%> value="<%=skilID%>" >
<%
}

تحياتي

مدني

هذا الموضوع مغلق.

مواضيع مشابهة