开发者

Database Based Templating System

开发者 https://www.devze.com 2023-04-12 20:59 出处:网络
As a part of a script I\'m writing I would like to add a templating system where the variables are derived from a database table like this:

As a part of a script I'm writing I would like to add a templating system where the variables are derived from a database table like this:

id int auto_increment primary key, 
name varchar(200) not null, 
value float(6,2) not null

My problems are:

1- I am not able to find a way that makes it user-friendly to display those variables when editing a page & I don't know how many variables there would be so I cannot add all-in-one form.

2- I don't know how the variable should be saved to the database (I'm looking to save a refere开发者_JAVA百科nce of the variable not its value so when it's updated on the table, all pages that uses it will have the new value) ... but using the variable number doesn't seem to be clear on what it holds when someone first looks into the page while editing.

3- Should I use something like preg_replace to replace those variables or is there a better method to do that?


If i understand your question correctly, you are seeking a way to extract column definitions from your database to build a web form regarding to the fields defined in a database table? if this is the case, you can obtain the structure easily with

SHOW COLUMNS 
FROM database-table

Even better would be to use the information_schema database (available since MySQL 5.x), because you wont have to parse anything from it:

SELECT * 
FROM   information_schema.columns 
WHERE  table_name = "database-table"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号