Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Document Template system with PHP

Status
Not open for further replies.

webslinga

Programmer
Jun 20, 2006
55
US
I have a rather interesting problem on my hands and I was hoping that this forum might give me some good ideas on it.

I would like to develop an application that allows a .html and a .pdf document to be filled with "variables" that is enclosed with a { variable_name } that a person using my application can set dynamically.

So, for example, if an operator of my application sets a portion of the template to dynamically input the firstname of a guest in our user table, the variable in a .pdf file would be { user.firstname } Then the PHP script will be designed to read from the table user and grab the firstname field and replace it with 'user.firstname'

Pretty simple so far right? Here's the catch...

I need to figure out a really nice way to reveal to the people using our system what variable names are allowed WITHOUT revealing to them the underlying database structure and WITHOUT having the programmer to continually maintain a list of allowable variables.

Any feedback would be appreciated all. I thank you in advance.
 
I am not sure if this is what you are after, but it is similar-ish and may help.

I created an application and wanted to make CSS configurable and stored in mySQL db.

I ended up by making a table with 3 rows: configName, configDescription, configValue

There are many rows of data something like: calBackGround, Calendar Background, #FF0000

Setting it up like this, I can a description and the value without revealing the field name...which you can obviously make even more obscure if you want.

Now here is the tricky bit. I build the edit web page on the fly grabbing the fields from the database.
Code:
$strSQL = "SELECT * from config_menu";
	$menu = mysql_query($strSQL, $database) or die(mysql_error());
	$row_menu = mysql_fetch_assoc($menu);
	$totalRows_menu = mysql_num_rows($menu);

	$arrayValues = array(array());
	do{
				$arrValues [$row_menu["configName"]]["value"]=$row_menu["configValue"];
				$arrValues [$row_menu["configName"]]["name"]=$row_menu["configName"];
				$arrValues [$row_menu["configName"]]["description"]=$row_menu["configDescription"];

		}
	while($row_menu=mysql_fetch_assoc($menu));
Which builds a multi dimensional array.

Then to display it all:
Code:
<?php
while($row_result = mysql_fetch_assoc($result))
{
	
        echo chr(13).chr(10)."<tr><td nowrap>" . $row_result["configDescription"] . "</td><td>";
		
?>
      <input id="pick<?php echo $row_result["configName"]; ?>field" size="7" title="theColour" name='<?php echo $row_result["configName"]; ?>' value='<?php echo $row_result["configValue"]; ?>'>
      
      <?php 
}
?>

I have snipped a bit where there is a colour picker implemented, but you should get the idea.

I hope it helps.

Steve Davis

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top