SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CheckBox's Validation Thru Database....!

    Hi Everyone...!
    The Subscribers on my Web-Site need to Personalize their Settings so as to Only View the Categories(Pertaining to Tendering) of their Interest by Selecting them thru Checking the CheckBoxes, HowEver they may Change the preferences(for Personalization) at any point of time by Re-Selecting few other Categories or Deselecting the Previous Selected Categories.
    The Page looks something like....(Though the Original Page will be .ASP with SQLServer Database)
    http://www.milad.net/PersonalizeMy.htm

    I've the Following two Tables
    1) Personalization
    SubscriberID (a Unique Subscriber ID assigned to every Subscriber)
    SelectedSubSections (For Values of Selected CheckBoxes For Categories, Seperated by ; )
    EmailSubSEctions ( For Values of Selected CheckBoxes For E-mail Categories Seperated by

    2) TenderSubCategor
    SubCategoryId (a sequence Number given to all the Categories)
    SubCategoryName ( the Name of the Category)
    For E.g. the Above Table has the values like....

    SubCategoryID SubCategoryName
    1 Buildings
    2 Combustion Fuels
    3 Med & Lab Equipments
    4 Office Equipments
    5 Paints & Insulations
    And so on Upto 50 as all listed in the table on above page...

    How Could I achieve the task of saving the selected categories to the table and when the user changes his mind to re-select few other categories and Deselect from those selected earlier...
    when he comes to the Personalization page from links thru other pages, I want to show him his selected Categories "CheckBoxes Selected" and Allow him to further manipulate the Personalization table as stated above with respect to his selection......????????????

    Besides, when the Subscriber finalizes his selection of Categories, he's being re-directed to Viewmy.asp page .... for E.g. how the page looks like, pls visit ....

    http://www.milad.net/ViewMy.htm

    Here it shows only the Categories Being selected by the Subscriber...with Total Tenders Available and Tenders Added today... Here I Only need the Table Design which would facilitate me to display the user's selected Categories(Here in this case I've displayed 33 Categories Out of 50) in the format displayed in ViewMy.htm page... I've already got the Values for Total & Added Tenders today...

    I'm ready to provide any further information required and would be pleased to seek your help
    Thanks in advance...!
    Regards

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    well you can use a data grid of some sort. Use loop or do while to list all the items within the tendersubcat table, and add a checkbox to it.

    ie:#
    Code:
    <%
    
    	Dim Connection
    	Set Connection = Server.CreateObject("ADODB.Connection")
    	    Connection.Open "DSN"
    
    	Dim Recordset_cat
    	Set Recordset_cat = Server.CreateObject("ADODB.Recordset")
    	    Recordset_cat.Open "SELECT * FROM categories", Connection, 2, 2
    
    	Dim Recordset_user
    	Set Recordset_user = server.createobject("ADODB.Recordset")
    	    Recordset_user.open "SELECT * FROM User_settings WHERE UserID = '" & Session("User") & "'", Connection, 2, 2
    
    	IF not Recordset_user.eof then
    
    		response.write("<table>")		
    
    		do while not Recordset_cat.eof
    
    			response.write("<tr><td>" & Recordset_cat("Cat_Name") & "</td><td>")
    			response.write("<input type=""checkbox""" & if instr(Recordset_user("personal_selection"),Recordset_cat("Cat_Name")) then response.write(" checked") & " value=" & Recordset_cat("Cat_ID") & ">") 
    			response.write("</td></tr>")
    
    		Recordset_cat.movenext
    		Loop
    
    		response.write("</table")
    
    	ELSE
    
    		Response.write("Unable to display categories. Please contact your administrator")
    
    	END IF
    
    %>
    What this will do is throw out all the values in the database providing you create a recordset with the same names as above.

    It will create a table all the way down with the SubCategoryName in the left and then the checkbox with the category id as the value.

    As for having the checkboxes already checked, this is easy but you would have to split the users personalized settings into an array using array = split(SelectedSubSections,";") then it would be the challenge of matching them.

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello gRoberts...
    To give you an Idea as to what I've done so far.. and where I'm facing the problem, Let me put the code here.. whereby you can be in a better position to guide me achieve my task...

    <%
    Dim SubCategoryId, iCounter
    Dim cnMilad, rsRst, strSQL

    Set cnMilad = Server.CreateObject("ADODB.Connection")
    cnMilad.CursorLocation = 3
    cnMilad.Open Application("dbConString")
    %>
    <!-- #include virtual="/Libs/IsLogged.asp" -->
    <%

    Dim SubId, bFlag

    SubId = Session("SubId")
    If SubId = "" Then
    Response.Redirect "/NeedLogin.asp"
    End If

    ' Find Out If the Subscriber already personalised or not
    strSQL = "SELECT * FROM Personalization WHERE SubscriberId = " & SubId
    Set rsRst = cnMilad.Execute(strSQL)

    If rsRst.RecordCount = 1 Then

    ' SectionsList Dimension will be 50 (Max Number of Personalized Sections Avialable)
    Dim List, SectionsList(50)

    List = split(rsRst("SelectSubSections"), ";")
    For iCounter = 0 to UBound(List)
    SectionsList(List(iCounter)) = True
    Next

    bFlag = True

    End If
    %>


    <%
    ' Release rsRst if Any
    Set rsRst = Nothing
    strSQL = "SELECT SubCategoryId FROM TenderSubCategory WHERE (Personalize = 1)"
    Set rsRst = cnMilad.Execute(strSQL)

    ' We Uses sSelected to enable checkbox
    Dim sSelected

    ' With the Help from SectionsList

    If bFlag = True Then
    If SectionsList(rsRst("SubCategoryId")) = True Then
    sSelected = " checked "
    Else
    sSelected = ""
    End If
    End If

    %>

    Now, I've these CheckBoxes Designed on the page, which I want to be only checked by the sSelected Values and not the others and these Values to be passed successfully to the next page, that is UpdateMy.asp
    <tr>
    <td bgcolor="#CECEFF" height="40" align="center">
    Buildings</td>
    <td bgcolor="#CECEFF" height="40" align="center">
    <INPUT type=checkbox name="SubSection<%= rsRst("SubCategoryId") %>" <%= sSelected %>></td>
    <td bgcolor="#CECEFF" height="40" align="center">
    Combustion Fuels</td>
    <td bgcolor="#CECEFF" width="33" align="center">
    <INPUT type=checkbox name="SubSection<%= rsRst("SubCategoryId") %>" <%= sSelected %>></td>

    .......... SO On Upto 50 CheckBoxes and Category names...,I'm not getting any idea as to where if at all I use any Do ....While or For ....Next Loop with the CheckBoxes here or not.....????????Since the SubCategoryId seems to getting a common value whereby I can see all the CheckBoxes Checked, whereas I want Only those to be checked which values are coming from the Database where I've stored them in SectionsList(List(iCounter)) ...


    The UpdateMy.asp page ....

    Here I'm not getting any value if I write
    Response.Write Request("SubSection") .....

    <%
    Dim SubId

    SubId = Session("SubId")

    ' Delete Any Personalisation
    strSQL = "DELETE FROM Personalization WHERE SubscriberId = " & SubId
    Set rsRst = cnMilad.Execute(strSQL)

    Dim strPSections

    'Collect All the Information

    Dim rsTemp
    'Get the IDs of Personalised Sections
    Set rsTemp = Nothing
    strSQL = "SELECT SectionId, SectionName FROM Sections WHERE (Personalize = 1)"
    Set rsTemp = cnMilad.Execute(strSQL)

    strPSections = ""
    While Not rsTemp.EOF
    'Check if the Sections is enabled then add it to the strPSections
    If Request("SubSection" & rsTemp("SectionId")) = "on" Then
    strPSections = strPSections & rsTemp("SectionId") & ";"
    End If
    rsTemp.MoveNext
    Wend

    ' Add All That to the Database
    Set rsRst = Server.CreateObject("ADODB.Recordset")
    strSQL = "SELECT * FROM Personalization WHERE SubscriberId = " & SubId
    rsRst.Open strSQL, cnMilad, 2, 3
    rsRst.AddNew
    rsRst("SubscriberId") = SubId

    rsRst("SelectedSections") = strPSections

    rsRst.Update
    rsRst.Close

    Set rsRst = Nothing
    cnMilad.Close
    Set cnMilad = Nothing
    Response.Redirect "/My/ViewMy.asp"
    %>

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok scrap the sSelected coding, as your first issue would be it's only hitting the first record, you haven't inserted a loop to carry it on.

    Also, as your using a variable, it will fail its purpose as each checkbox will have the value of the last record checked.

    Hense why I suggested dynamically creating a table.

    Best thing to do is zip up your project files ( images not really needed, but don't worry if you send them ), then I can look at it, clone the page and make the changes so you can see the difference between the two.

    Which means you can learn from the support.

    If you send it to the following address: Admin* Antispam *eycdwebdesign.co.uk

    * Note, remember to replace * Antispam * with @.

    Kind regards


    Gavin


Bookmarks

Posting Permissions

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