navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

drop down giving more results then wanted

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> drop down giving more results then wanted
Page: [1]
 
crosscreek

 

Posts: 107
Joined: 2/5/2008
Status: offline

 
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

 

Posts: 26597
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
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> 


_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to crosscreek)
crosscreek

 

Posts: 107
Joined: 2/5/2008
Status: offline

 
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.


(in reply to Spooky)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> drop down giving more results then wanted
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts