Print Page | Close Window

if, elseif, else

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=21481
Printed Date: 29 March 2026 at 8:42am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: if, elseif, else
Posted By: pjb007
Subject: if, elseif, else
Date Posted: 04 October 2006 at 8:50pm
Anyone see whats wrong with this
 

 if request("state") = "test" then
sSQL="SELECT * FROM computer ORDER BY siteTitle"
 elseif request("state") = "test2" then
sSQL="SELECT * FROM computer ORDER BY id"
 
 else request("state") = "test3" then
sSQL="SELECT * FROM computer ORDER BY url"
 end if
 
 
Thats just test code once I get the if statements working they will be used for selecting items instead.



Replies:
Posted By: Scotty32
Date Posted: 04 October 2006 at 10:12pm
if thats a direct cut and paste then the problem is with the part in red missing an IF

in future it might be better to paste the error message aswell

if request("state") = "test" then
sSQL="SELECT * FROM computer ORDER BY siteTitle"

 elseif request("state") = "test2" then
sSQL="SELECT * FROM computer ORDER BY id"

 

 else request("state") = "test3" then
sSQL="SELECT * FROM computer ORDER BY url"

 end if



but i think it might be better to have



select case request("state")
    case "test"
        sSQL="SELECT * FROM computer ORDER BY siteTitle"
    case "test2"
        sSQL="SELECT * FROM computer ORDER BY id"
    case "test3"
        sSQL="SELECT * FROM computer ORDER BY url"
end select




-------------
S2H.co.uk - http://www.s2h.co.uk/wwf/" rel="nofollow - WebWiz Mods and Skins

For support on my mods + skins, please use http://www.s2h.co.uk/forum/" rel="nofollow - my forum .


Posted By: pjb007
Date Posted: 04 October 2006 at 10:24pm
Thanks for that that works great.
 
I have added a case at the start that applies when the case = "" (blank) and also a case else for all others.
 
Smile


Posted By: dpyers
Date Posted: 05 October 2006 at 1:20am
If then statements are pretty slow. A case statement is many times faster.

Also, if you're using the request object, it's a good practice to trim it to remove any leading or trailing spaces - e.g. Trim(Request("state").

Another good practice is specifying Request.Form (assuming state is a form field) as that will keep someone from entering the info via a url query string and perhaps bypassing any validation or security. Spammers like contact forms that just use the request object instead of specifying request.form.


-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net