Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with displaying recordset results

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,
I'm trying to display results based on a form. Everything works until the last few lines where I'm trying to display a database field. Can anyone tell me why this code isn't working? I get the error expected end when I include the last 4 lines. Any help is very much appreciated.


<%
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;0&quot; then
response.write &quot;Eff&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;1&quot; then
response.write &quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;type&quot;)=&quot;2&quot; then
response.write &quot;1 Study&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;3&quot; then
response.write &quot;2&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;4&quot; then
response.write &quot;3&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;5&quot; then
response.write &quot;4&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;%&quot; Then
response.write &quot;Recordset1.Fields.Item(&quot;Bedrooms&quot;).Value&quot;
End If %>
 
Do not put quote marks around the reference to the recordset value. It is like a variable. If you surround it with quotes it becomes a string. With the quotes around Bedroom you have something that VBScript interprets as three statements.

Code:
Response.write &quot;response.write Recordset1.Fields.Item(&quot;

Bedrooms

&quot;).Value

The first one is valid, but probably not what you wanted.
The second one may be valid but it does nothing.
The third one needs a closing quote, it is an unterminated string.

The last statement suggests an expected end error. But I wonder about using the % symbol in ASP, even in quotes, since it is a special character, part of the ASP start and end tags. Can you pick another character to use for this purpose.

Code:
If  Recordset1.Fields.Item(&quot;Type&quot;)=&quot;-1&quot; Then
     response.write Recordset1.Fields.Item(&quot;Bedrooms&quot;).Value  
      End If
 
Thanks for the input. Is there a way to pick another character to replace &quot;%&quot; when I need that character to search all fields when the user clicks all?
 
As I showed in my example, use a value like -1. How are you searching all fields?

Anyway, the % is probably not the problem. It is just good practice to avoid keywords and special symbols in data and names of variables.

Did the script work when you deleted the quote marks?
 
It seems that using &quot;%&quot; is the problem. When I replace it with another value the script works fine after deleting the quote marks. The problem is that I need the &quot;%&quot; for my query which is below. For the Type one of the selections is all so I need to use % for the query. Please help,

SELECT Apartment_Info.Apartment_ID, Apartment_Info.Apartment_Name,Apartment_Info.Area, MIN(Unit_Info.Low_Price) AS Starting_Price, Apartment_Info.YearBuilt, Apartment_Info.Bedrooms, Unit_Info.Type
FROM Apartment_Info INNER JOIN Unit_Info ON Apartment_Info.Apartment_ID = Unit_Info.Apartment_ID
WHERE Type LIKE 'varType' AND (Area LIKE 'varNorth' OR Area LIKE 'varNorthwest' OR Area LIKE 'varNorth_Central' OR Area LIKE 'varSouthwest' OR Area LIKE 'varCentral') AND Apartment_Name LIKE 'varName' AND Zip Like 'varZip' AND District LIKE 'varDistrict' AND Pools LIKE 'varPools' AND Washer_Dryer LIKE 'varWasher_Dryer' AND Access_Gates LIKE 'varAccess_Gates' AND Jacuzzi LIKE 'varJacuzzi' AND Microwave LIKE 'varMicrowave' AND Fireplace LIKE 'varFireplace' AND Pet LIKE 'varPet' AND Large_Pet LIKE 'varLarge_Pet' AND Fitness_Center LIKE 'varFitness_Center' AND Covered_Parking LIKE 'varCovered_Parking' AND Garage LIKE 'varGarage' AND Conn LIKE 'varConn' AND Prov LIKE 'varProv' AND Elementary_School LIKE 'varElem' AND Middle_School LIKE 'varMid' AND High_School LIKE 'varHigh' AND Basketball LIKE 'varBasketball' AND Alarms LIKE 'varAlarms' AND Water_Volleyball LIKE 'varW_Volleyball' AND Tennis LIKE 'varTennis' AND Vaulted_Ceilings LIKE 'varVaulted_Ceilings' AND Jogging_Trail LIKE 'varJogging_Trail' AND Sauna LIKE 'varSauna' AND Raquetball LIKE 'varRaquetball' AND Garden_Tub LIKE 'varGarden_Tub' AND Volleyball LIKE 'varVolleyball' AND Clubroom LIKE 'varClubroom' AND Business_Center LIKE 'varBusiness_Center' AND Attached_Garage LIKE 'varAttached_Garage' AND View LIKE 'varView' AND Laundry LIKE 'varLaundry' AND Patio_Balconet LIKE 'varPatio' AND Low_Price >=varLow_Price AND High_Price <= varHigh_Price GROUP BY Apartment_Info.Apartment_Name, Apartment_Info.Area, Apartment_Info.YearBuilt, Apartment_Info.Bedrooms, Apartment_Info.Apartment_ID, Unit_Info.Type

 
Hello again,
How could the script be rewritten so that if none of the other conditions are met then response.write Recordset1.Fields.Item(&quot;Bedrooms&quot;).Value


<%
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;0&quot; then
response.write &quot;Eff&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;1&quot; then
response.write &quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;type&quot;)=&quot;2&quot; then
response.write &quot;1 Study&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;3&quot; then
response.write &quot;2&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;4&quot; then
response.write &quot;3&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;5&quot; then
response.write &quot;4&quot;
end if
If none of these other conditions are met then
response.write Recordset1.Fields.Item(&quot;Bedrooms&quot;).Value
How could I do that? Thanks a lot for your help.
 

flag=&quot;0&quot;
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;0&quot; then
response.write &quot;Eff&quot;
flag=&quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;1&quot; then
response.write &quot;1&quot;
flag=&quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;type&quot;)=&quot;2&quot; then
response.write &quot;1 Study&quot;
flag=&quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;3&quot; then
response.write &quot;2&quot;
flag=&quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;4&quot; then
response.write &quot;3&quot;
flag=&quot;1&quot;
end if
If Recordset1.Fields.Item(&quot;Type&quot;)=&quot;5&quot; then
response.write &quot;4&quot;
flag=&quot;1&quot;
end if
If flag=&quot;0&quot; then
response.write Recordset1.Fields.Item(&quot;Bedrooms&quot;).Value
end if

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top