abthomas
May 15th, 2009, 09:25 AM
Hello,
I want to do a select which takes into account a dynamic number of 'and's.
Eg:
Table 'People' holds Names and a 'likes' textfield
Table 'Likes' holds a list of numbers and 'likes': '1 - Chess', '2 - Poker' and '3 - Bridge'.
So if person 'Bob' likes Chess & poker his likes-text field holds '12', if 'Jane' likes all three her likes-text field holds '123'.
I present the user with check boxes for the list of likes, but I'm not sure how to build the select. It could read 'Select Name from People left inner join on likes where number=1' if they just want to see people who like Chess or 'Select Name from People left inner join on likes where ( number=1 or number=2 or number=3)' if they select all tick boxes.
I've got asp.net to dynamically add the checkboxes (so I just add another 'like' (eg 'basketball) and it'll add a checkbox to the screen), and I've worked out how to read the data in the checkboxes.
Should I just have a base select string 'Select Name from People left inner join on likes' and then add the data in the loop eg (pseudo code):
string = 'Select Name from People left inner join on likes'
Loop around the repeater.
if they've ticked the current box
string = string + "where number=" + tickboxnumber
endif
endloop
Or is there a better way?
Many thanks.
I want to do a select which takes into account a dynamic number of 'and's.
Eg:
Table 'People' holds Names and a 'likes' textfield
Table 'Likes' holds a list of numbers and 'likes': '1 - Chess', '2 - Poker' and '3 - Bridge'.
So if person 'Bob' likes Chess & poker his likes-text field holds '12', if 'Jane' likes all three her likes-text field holds '123'.
I present the user with check boxes for the list of likes, but I'm not sure how to build the select. It could read 'Select Name from People left inner join on likes where number=1' if they just want to see people who like Chess or 'Select Name from People left inner join on likes where ( number=1 or number=2 or number=3)' if they select all tick boxes.
I've got asp.net to dynamically add the checkboxes (so I just add another 'like' (eg 'basketball) and it'll add a checkbox to the screen), and I've worked out how to read the data in the checkboxes.
Should I just have a base select string 'Select Name from People left inner join on likes' and then add the data in the loop eg (pseudo code):
string = 'Select Name from People left inner join on likes'
Loop around the repeater.
if they've ticked the current box
string = string + "where number=" + tickboxnumber
endif
endloop
Or is there a better way?
Many thanks.