handling vars in prewritten scripts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

handling vars in prewritten scripts

Post by danwguy »

Ok, let's say I have a script builder, where a manager can build a script for people to read, but he wants variables in it like.... "Thank you for calling $business_name I am $username, How can I help you today?" now those variables have to mean different things depending on who is viewing them, and they are alot more complicated than just getting a username and storing it as a variable. The place has 5 different dba's and multiple scripts for each dba, but they want to define those variables in a management console. What would be the easiest way of going about something like this? My fist though was to build a file called definitions.php and include it in the page depending on what dba they log in to, but upgrading that seems to be a little difficult. I hope I am explaining this correctly, it seems to be a big problem to me, but I am sure someone has faced this before elsewhere. One specific example is if someone logs in as part of one dba the variable $product has to be "Google", but if they log in as a different dba the same variable $product has to be "Bing". For some reason I can't wrap my head around this. Thank you in advance for any help.
ouchiko
Forum Commoner
Posts: 35
Joined: Sun Oct 09, 2011 6:54 pm
Location: London

Re: handling vars in prewritten scripts

Post by ouchiko »

If I'm understanding it correctly then the optimal solution would be a database table.

In the user table for the dbas add each account with a field of "class", e.g. Dba1, power user, googleman, bingman.

Create another table which acociates a class with a series of variable names

ID, keyName, value, className
1, productName, Google, googleman

Then, when they login, scan the table for all className=xyz and use keyName and value to correctly populate the variables.

At least this way it's a db managed section and doesn't require code updates to make changes.

That is if I've understood your problem.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: handling vars in prewritten scripts

Post by danwguy »

that's exactly what I was talking about, I had thought about a db storage method but after programming all of what I am doing right now for some reason my brain couldn't wrap itself around getting those vars back out as the appropriate var names, but that works perfectly. Thank you.
Post Reply