PDA

View Full Version : Duplicate items in form, need to get rid of.


JustAsking
05-01-2003, 06:12 AM
I have two tables in a SQL database: NF_Populate, NF_Results.

I have created a form where the user fills out the form using dropdown boxes, check boxes etc, the dropdown boxes and other elements are populated from the table NF_Populate. The user then submits the form and the results are recorded in table NF_Results. I allow the user access to the form again, but when they use the form a second time I want to allow them to change their original selection stored in table NF_results to another selection. I am able populate the dropdown boxes from the data in table NF_Populate, but I also want to have the dropdown box initially select the item from table NF_Results. I can do this but I find I then have duplicate values in the dropdown box, one from table NF_Results and the from NF_Populate. How can I make it so only the item from table NF_Results is in the dropdown box.

Any further explanation required, please let me know.

Cheers.

raf
05-01-2003, 09:46 AM
Well, inside the loop that builds the optionlist for the dropdown, you have a check to see if the value (or description) of that row from the recordset, has the same value as the one in your NF_results table.

So you need to have that value (by running an extra select, or from a (hidden) formfield on the previous page, or a sessionvaraiable or from the querystring.

Here is some code where i used two selects


if rsDikte.EOF=true then
Response.Write("Er kon geen keuzelijst met diktes gegenereerd worden. ")
else
do while rsDikte.EOF=false
if rsDikte.Fields("number") = rsArtikels.Fields("number") then
Response.Write("<option value=" & rsDikte.Fields("number")& " selected>" & server.HTMLEncode(rsDikte.Fields("dikte")) & " mm")
else
Response.Write("<option value=" & rsDikte.Fields("number")& ">" & server.HTMLEncode(rsDikte.Fields("dikte")) & " mm")
end if
response.write("</option>")
rsDikte.MoveNext
loop
end if


<edit> italic is added </edit>

Spudhead
05-01-2003, 09:48 AM
How can I make it so only the item from table NF_Results is in the dropdown box.

You don't mean this, do you? You mean to have the item from NF_Results selected, and the remaining options made up from everything out of NF_Options EXCEPT whatever has already been pulled out of NF_Results.

At least, I hope you do. :)

First run the SQL to get the relevant field value out of NF_Results. Put it into a variable ("myResultsValue"), and write an <option SELECTED> tag using it. Run another query to get everything out of NF_Options. Loop through that recordset:

<%
while not rsOptions.EOF
myOptionsValue=rsOptions.Fields("fieldName").value
if myOptionsValue<>myResultsValue then
%>
<option value="<%=myOptionsValue%>">myOptionsValue</option>
<%
end if
rsOptions.moveNext
wend
%>


That should do it. Any help?





Edited to add: Aaaaah, beaten to it :D :rolleyes:

raf
05-01-2003, 10:22 AM
<edit>we both crossed eachothers posts </edit>

You don't mean this, do you? You mean to have the item from NF_Results selected, and the remaining options made up from everything out of NF_Options EXCEPT whatever has already been pulled out of NF_Results.

Thats exactly what my code does :D

rsArtikels.Fields("number") --> the value for variable in NF_Results. Lets say 5
rsDikte.Fields("number") --> a value from the recordset that contains all values for this variable (from NF_Populate). Say this recordset contains 10 records with the values 1,2,3,4,5,6,7,8,9,10

This code will build an optionlist like
<option value="1">one
<option value="2">two
<option value="3">three
<option value="4">four
<option value="5" selected>five
<option value="6">sic
<option value="7">seven
<option value="8">eight
<option value="9">nine
<option value="10">ten

On the screen, you'll see a dropdown, with "five" (or whatever other description). If you display the optionlist, you'll have it in the 1 to 10 order. (which is in most cases better then 5, 1,2,3,4,6,7,8,9,10)

But i now see, the option closing tag was missing, so i'll slip that in