0

Sorry for the ambiguous title, not quite sure how to explain this. Basically what I have is an ASP page that will dynamically build a 'form' based upon information from a Database. The DB holds information such as what type of options to give the user (radial, checkboxes, drop down, text box...) along with what the information that should be displayed.

All of this builds perfectly fine. However, now I have a situation in which I want to add in that the DB will also store known variables to assign to certain sections. For example, if we know the logged in user is 'Danny' then any place within the forms that it loads, I want it to grab my name.

So in the DB I added a new column for these sections which indicates what variable to call. However, if I simply 'grab' this variable from the DB it is simply going to print it. How can I pass the variable that I am grabbing from the DB and tell my ASP page that I want it to use a matching variable that it has.

I am hoping to avoid using something as static as If or Case statements. The ultimate goal is for the variable we are grabbing from the first table to be able to inform the ASP page of what variable to use from another DB call it is making.

For example: The first DB call is to 'rsForms' and the second DB call is 'rsEmployee'. The rsForm("question") is 'First Name' and within that rsForm("variable") column we put 'FirstName'. The hope being that we could do something like rsEmployee("rsForm("Variable")").

So each time that the rsForms("Variable") field is not null, it would use a separate statement which is prefilling the value of the Form with the information from rsEmployee using the field that is being specified by the rsForms("Variable") value.

Talion83
  • 47
  • 1
  • 1
  • 6
  • Hrmm. You'll need to explain better. Is the value you fetch from the first database, the name of a table or something in the second database? – MJM Jul 09 '13 at 16:54
  • This gets asked a *lot* in many different ways and unilaterally the answer tends to be that there is a better way to accomplish what you're trying to accomplish. Dynamic variable names are impossible to achieve in most languages and even where possible they're difficult to work with. It's difficult to give specific advice without seeing an example of how or why you need this, though. – David Jul 09 '13 at 16:56
  • I wouldn't really recommend this, but... You could create a dictionary object that holds all your page variables. Then when you call dict.item("YourPageVar") from the db just call dict.item(someDBvaluethatEqualsYourPageVar) – safetyOtter Jul 09 '13 at 21:37
  • For example: The first DB call is to 'rsForms' and the second DB call is 'rsEmployee'. The rsForm("question") is 'First Name' and within that rsForm("variable") column we put 'FirstName'. The hope being that we could do something like rsEmployee("rsForm("Variable")"). – Talion83 Jul 10 '13 at 17:40

1 Answers1

0

I would suggest using JSON for the values, since the data can be easily shared on both the client/server. Store the JSON data as a text field in the DB.

See: Any good libraries for parsing JSON in Classic ASP?

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • I am not familiar with using JSON, but I can pass this along to our main programmer to have a look into. – Talion83 Jul 10 '13 at 17:44