TwelvestoneBack End

ASP VBScript split function


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Suzy
 
2010-04-09

Hi guys, I have this bit of ASP code

'Get restaurant ID's from varaible pRestaurant by splitting either side of comma pRestaurantSplit = Split(pRestaurant, ", ")

'Initialise the strSQL variable with an SQL statement to query the database strSQL = "SELECT * FROM Members INNER JOIN Restaurants ON Members.RestaurantLocation=Restaurants.RestaurantLocation WHERE Members.Approved='Yes' AND " for each x in pRestaurantSplit

    strSQL = strSQL + " OR Restaurants.RestaurantID='" & x & "'"
next
strSQL = strSQL + "ORDER BY " & pSort & " " & pOrder & ";"

I need it so that if x is the first item it doesn't have the OR before it or alternatively it it is the last item then write it slightly different. How do I find if it's the first or last item?

Hope that makes sense! Thanks k

jamiec
 
2010-04-09

Instead of using a foreach, use a for so you have an "index" number - and then use simple boolean logic to determine if you're at start/end of list.

jeez my VBS will be rusty, but something like:

numItems = LEN(pRestaurantSplit) for i = 0 to numItems-1 ' use i=0 or i=(numItems-1) to determine first/last next

Technomancer
 
2010-04-09

or instead of splitting, you could replace the delimeter with the sql:

pRestaurant = "1,3,5,7,9"

strRestSQL = replace(pRestaurant,",","' OR Restaurants.RestaurantID='")

strSQL = "SELECT * FROM Members INNER JOIN Restaurants ON Members.RestaurantLocation=Restaurants.RestaurantLocation WHERE Members.Approved='Yes'"

if len(pRestaurant) > 0 then strSQL = strSQL & " AND Restaurants.RestaurantID='" & strRestSQL & "'" end if

Suzy
 
2010-04-09

Cheers guys, I'll give it a try k

poliguin
 
2010-04-09

why not use IN?

strSQL = "SELECT * FROM Members INNER JOIN Restaurants ON Members.RestaurantLocation=Restaurants.RestaurantLocation WHERE Members.Approved='Yes' AND Restaurants.RestaurantID IN (" & pRestaurant & ") ORDER BY " & pSort & " " & pOrder & ";"

[edit] and this is the anal part of me, naturally you would want to sanitize in put using something like:

[\d|,]{1,}$

Suzy
 
2010-04-09

Ahhh poliguin that worked a treat!!! Thank you so much k As usual I was taking the longest route possible to get what I needed when there was something so much simpler k

Thanks again and to Techno and Jamie too k

At least I have learnt a few things through all this k

Candy Beard
 
2010-04-10

Originally posted by: poliguin [edit] and this is the anal part of me, naturally you would want to sanitize in put using something like:

[\d|,]{1,}$

http://imgs.xkcd.com/comics/exploits_of_a_mom.png

DontBogartMe
 
2010-04-10

Seal the perimeter! There's an intruder in the Back End!

poliguin
 
2010-04-11

Originally posted by: mclarkson

http://imgs.xkcd.com/comics/exploits_of_a_mom.png

i <3 that comic.

as a random side, for quite a while I've been overly paranoid about XSS and SQL injection. The funny caveat for that is that I knew about one part of previous work where I wasn't so good about coding against it. Fast forward a little bit and I find out that the place I knew was totally vulnerable took an entire site down due to the vulnerability (and it isn't exactly a small site, but also not a huge site). One of those items you learn and live from.

Stmoo
 
2010-04-11

Originally posted by: mclarkson

http://imgs.xkcd.com/comics/exploits_of_a_mom.png

No self-respecting database architect would name the table as a plural. It should be "Student". k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

ASP VBScript split function