drop down giving more results then wanted (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


crosscreek -> drop down giving more results then wanted (3/23/2008 20:13:26)

I have set up a drop down list for the gender of a dog.

My table is set up with ID, Gender
1 = unknown
2 = Male
3 = female

When a dog is entered the default value is 1 (unknown)

My edit dog page is has this

SQL = "SELECT tblDOG.ID AS ID, tblDOG.name as name, tblDOG.PreTi AS preti, tblDOG.SuffTi as suffti, tblDOG.callname as callname, " _
& " tblDOG.DOB as Birth, month(DOB) AS BM, day(DOB) AS BD, year(DOB) AS BYR, tblDOG.Owner as owner, tblDOG.Breeder as breeder, tblDOG.DOD as death, " _
& " tblDOG.website as website, tblDOG.Hips as hips, tblDOG.Eyes as eyes, tblDOG.elbow as elbow, tblDOG.CNM as cnm, " _
& " tblDOG.UKC as ukc, tblDOG.AKC as akc, tblGEN.GenID as genderID, tblColor.ColorID as colorid " _
& " FROM tblGEN RIGHT JOIN (tblColor RIGHT JOIN tblDOG ON tblColor.ColorID = tblDOG.ColorID) ON tblGEN.GenID = tblDOG.genID " _
& " WHERE ID="& Request.querystring("ID")

My drop down for the gender code is

<SELECT name="genderid">
<%
'drop down boxes
SQL2 = "SELECT tblGEN.Gender AS gender, tblGEN.GenID AS genid , IF(tbldog.genID IS NOT NULL, '', ' SELECTED ' ) AS sel FROM tblGEN LEFT JOIN tblDOG ON tblGEN.GenID = tblDOG.genID ORDER BY tblgen.genid"
Set RS = myconn.Execute( SQL2 )
do until rs.eof
Gid = RS("genid")
gender = RS("gender")
Response.Write "<option selected VALUE=""" & gid & """>" & gender & "</option>" & vbNewLine
RS.MoveNext
Loop
RS.Close
%></select>

This gives me a long list of colors (I'm thinking all the dogs in the database) Unknown, unknown, female, male, unknown.......on & on

If I take out IF(tbldog.genID IS NOT NULL, '', ' SELECTED ' ) AS sel then I get the 3 colors shown & I can edit it fine, BUT it automatically selects Female each time when the editdog.asp page is shown. Basically someone would need to make sure the gender is correct before updating the dog.

Not sure how to get the sql to select the gender of the current dog only & the other 2 choices.


If dog is male:

Male selected, but unknown & female is also in the drop down.




Spooky -> RE: drop down giving more results then wanted (3/23/2008 23:38:33)

Generally speaking, you wont use a database query to display the drop down list - you will use the result from the record to define the content of the list
<SELECT name="genderid">
<option VALUE="1" <%If rs("Gender")="1" then response.write "selected"%>>Unknown</option>
<option VALUE="2" <%If rs("Gender")="2" then response.write "selected"%>>Male</option>
<option VALUE="3" <%If rs("Gender")="3" then response.write "selected"%>>Female</option>
</select> 




crosscreek -> RE: drop down giving more results then wanted (3/24/2008 9:48:07)

Thanks...HUG

You know I had something very similar set up the first time, but Didn't have the selected part on all the results.

So when I viewed the page only the gender that was in the database was selected, but the others didn't show up.

Thanks again.





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125