Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - if, elseif, else
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

if, elseif, else

 Post Reply Post Reply
Author
pjb007 View Drop Down
Groupie
Groupie


Joined: 03 September 2004
Location: United Kingdom
Status: Offline
Points: 185
Post Options Post Options   Thanks (0) Thanks(0)   Quote pjb007 Quote  Post ReplyReply Direct Link To This Post Topic: if, elseif, else
    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.
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post 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 - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
pjb007 View Drop Down
Groupie
Groupie


Joined: 03 September 2004
Location: United Kingdom
Status: Offline
Points: 185
Post Options Post Options   Thanks (0) Thanks(0)   Quote pjb007 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post 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.


Edited by dpyers - 05 October 2006 at 1:23am

Lead me not into temptation... I know the short cut, follow me.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.