#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Radio Buttons saved


    This is my code, i have a problem when i try to save the options that were selected previously by a user. Basically the main gist of this program is to save the radio options and when the user returns again he has to be able to see the one's which he has selected last time. But it shows array not found exception.So can you guys please suggest any code changes in the following code. Im in dire need of help, so awaiting for the positive replies.. and kindly reply asap.

    <body>
    <table border="1" cellpadding="1" cellspacing="1" bgcolor="#FF9933">
    </table>
    <cfquery datasource="BIOL1114" name="find_sections">

    SELECT sections.section , users.fname, users.lname
    FROM sections INNER JOIN
    users ON sections.uid_ta = users.uid
    WHERE sections.section > 0
    ORDER BY sections.section
    </cfquery>


    <cfform name="student_list" action="">
    <table border="1" cellpadding="1" cellspacing="1" align="center">

    <tr>

    <td colspan="3">

    <cfoutput query="find_sections">

    <a href="radio.cfm?section=#section#" class="sections">#section#</a>

    </cfoutput>

    </td>
    </table>
    </cfform>

    <cfform action="" name="group" >

    <cfif isdefined("section")>

    <cfquery name="Userinfo" datasource="BIOL1114">
    SELECT lname, fname, uid, section
    FROM USERS
    WHERE section = '#section#'
    ORDER BY lname
    </cfquery>
    <cfset checkarray=arraynew(1)>
    <cfloop index="i" from="1" to="#Userinfo.recordcount#">
    <cfset checkarray[i]=0>
    </cfloop>
    <cfset v1= ARRAYNEW(1)>
    <cfset v2= ARRAYNEW(1)>
    <cfset v3= ARRAYNEW(1)>
    <cfset v4= ARRAYNEW(1)>
    <cfset n=valuelist(Userinfo.lname)>
    <cfset n1= valuelist(Userinfo.fname)>
    <cfset n2= valuelist(Userinfo.uid)>
    <cfset n3= valuelist(Userinfo.section)>
    <cfset v1 = listtoarray(n)>
    <cfset v2 = listtoarray(n1)>
    <cfset v3 = listtoarray(n2)>
    <cfset v4 = listtoarray(n3)>
    <cfloop index="i" from="1" to="#Userinfo.recordcount#">
    <cfquery name="recheck" datasource="BIOL1114">
    SELECT *
    FROM grouping
    WHERE section='#section#' and uid='#v3[i]#'
    </cfquery>
    </cfloop>

    <cfif #recheck.groupnum# neq ''>
    <cfloop index="i" from="1" to="#arrayLen(checkarray)#">
    <cfset checkarray=listtoarray(#recheck.groupnum#,',')>
    </cfloop>
    </cfif>





    <table border="0" cellpadding="0" cellspacing="0" align="center" class="center" >

    <tr bgcolor="#000000" align="center" >
    <td colspan="2"><img src="../../../../images/biol1114_logo_black.gif"></td>
    <td class="head" bgcolor="#CCCCCC">Biology 1114 Class List :: Result - Section: <cfoutput>#section# </cfoutput></td>
    </tr>
    </table>
    <br /><br />
    <tr align="center" bgcolor="#FF6600">
    <table align="center" border="1" bordercolor="#0000CC" bgcolor="#FFCC99" width="600">
    <tr bgcolor="#FF6600">
    <td><B>Select Sections</B>

    <td><b>Last Name</b></td>
    <td><b>First Name</b></td>
    <td><b>UID</b></td>

    </tr>

    <cfloop from="1" to="#Userinfo.recordcount#" index="i">

    <tr align="center" bgcolor="#FFCC99">
    <td>
    1<input type="radio" name="rbgroup#i#" value="1" label="1" <cfif #checkarray[i]# eq 1>checked="yes"</cfif>>
    2<input type="radio" name="rbgroup#i#" value="2" label="2" <cfif #checkarray[i]# eq 2>checked="yes"</cfif> >
    3<input type="radio" name="rbgroup#i#" value="3" label="3" <cfif #checkarray[i]# eq 3>checked="yes"</cfif>>
    4<input type="radio" name="rbgroup#i#" value="4" label="4" <cfif #checkarray[i]# eq 4>checked="yes"</cfif>>
    5<input type="radio" name="rbgroup#i#" value="5" label="5" <cfif #checkarray[i]# eq 5>checked="yes"</cfif>>
    </td>

    <td><cfoutput>#v1[i]#</cfoutput> </font></td>
    <td><cfoutput>#v2[i]#</cfoutput></font></td>
    <td><cfoutput>#v3[i]#</cfoutput> </font></td>
    </tr>
    </cfloop>


    <tr align="center" bgcolor="#FF6600">
    <td colspan="4">
    <cfset a= #Userinfo.recordcount#>
    <cfinput type="hidden" name="v22" value="#a#">
    <cfinput type="submit" name="submit" value=" Group them!">
    <input type="hidden" name="ans1" value="#ans#" />
    </cfif>
    </cfform>
    </td>
    </tr>
    </table>
    </table>

    <cfif isdefined ("submit")>
    <cfquery name="Userinfo1" datasource="BIOL1114">
    SELECT lname, fname, uid, section
    FROM grouping
    WHERE section = '#section#'
    ORDER BY lname
    </cfquery>
    <cfset v3= ARRAYNEW(1)>
    <cfset n2= valuelist(Userinfo.uid)>
    <cfset v3 = listtoarray(n2)>
    <cfloop from="1" to="#form.v22#" index="i">

    <cfparam name="form['rbgroup' & i]" default="0">

    <cfset answers=arraynew(1)>



    <cfparam name="form['check' & i]" default="0">--->
    <cfquery name="update_groupnum" datasource="BIOL1114">
    UPDATE grouping
    SET groupnum=#form['rbgroup' & i]#
    WHERE uid='#v3[i]#'

    </cfquery>
    </cfloop>

    </cfif>
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    Hello. Since you're a first time poster, the first thing I'll ask is please don't just paste a huge file into a message and ask people to go through it all. If you're asking for help, you need to be courteous to us and take the time to pare down the code to only what is relevant to the problem.

    Next, you have to be more clear. What have you done yourself to try and figure out what's wrong? What is the actual error message you're getting? Which line is throwing the error?

    To be honest, I've been using CF for 14 years and I can still barely follow what is going on here. If the problem is in checkarray, and the array doesn't exist, then it could be the if block that surrounds that code which checks isDefined( "section" ). If section isn't defined, none of that code will run and your array will never be created.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    hey m sry about writing a huge code. i will not continue the same mistake in the future.

    And yes the code is generating an error in the checkarray[i], i changed the array creation code to a place where section is not required. but it still shows the same error.

    The element at position 2 of dimension 1, of array variable "CHECKARRAY," cannot be found.

    The error occurred in radio.cfm: line 125

    123 : <tr align="center" bgcolor="#FFCC99">
    124 : <td>
    125 : 1<input type="radio" name="rbgroup#i#" value="1" label="1" <cfif #checkarray[i]# eq 1>checked="yes"</cfif>>
    126 : 2<input type="radio" name="rbgroup#i#" value="2" label="2" <cfif #checkarray[i]# eq 2>checked="yes"</cfif> >
    127 : 3<input type="radio" name="rbgroup#i#" value="3" label="3" <cfif #checkarray[i]# eq 3>checked="yes"</cfif>>
    Last edited by cdeepthi; June 14th, 2012 at 08:11 PM. Reason: i was not clear
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    Hi,

    I worked on it , and i got a new error which is as follows

    omplex object types cannot be converted to simple values.
    The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.

    The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag.

    The error occurred in radio.cfm: line 90

    88 : <tr align="center" bgcolor="#FFCC99">
    89 : <td>
    90 : 1<input type="radio" name="rbgroup#i#" value="1" label="1" <cfif #checkarray[i]# eq 1 >checked="yes"
    91 : </cfif>>
    92 : 2<cfinput type="radio" name="rbgroup#i#" value="2" label="2" checked="no" >

    The following is the code used for arrays creation
    <cfset checkarray=arraynew(1)>
    <cfloop index="i" from="1" to="#Userinfo.recordcount#">
    <cfif #Userinfo.groupnum# neq ''>
    <cfset checkarray[i]=listtoarray(#Userinfo.groupnum#,',')>
    <cfelse>
    <cfset checkarray[i]=0>
    </cfif>
    </cfloop>

    Can you please tell me where did i go wrong? please reply asap! thank you and sorry for the inconvenience
  8. #5
  9. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    OK, but I still have no idea what all of this code is doing. It's very convoluted. Did you write this?

    I would try placing cfdumps in relevant locations, like before, inside, and after the loop that creates the array. Make sure it has the number of elements you expect and make sure the values are what you expect.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    yes.. i wrote the code. The basic gist is, user will select some radio option and when the user returns back it should display the option which he selected previously.

    I am trying with cfdump now, it works well when i am trying to save the radio options for the first time, but the code generates an error when i am trying to display already selected options. B'coz of the error, cfdump is also not working.

    Anyways thank you so much! i will keep trying
  12. #7
  13. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    Put a cfabort after your last cfdump to make sure you can see the dump output.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    Originally Posted by cdeepthi
    The basic gist is, user will select some radio option and when the user returns back it should display the option which he selected previously.
    That is quite common, but using a bunch of arrays to do it is not.
    Frankly I do not understand what the code is doing either. The fact that three developers are struggling with it does not bode well for future maintenance.. You might want to think about refactoring the code. So it is more intuitive and maintainable. If you decide to go that route, post the structure of the sections and grouping tables and a sample of the data.

IMN logo majestic logo threadwatch logo seochat tools logo