I think this might work (though I'm at school and I can't test it):
$dbh = CWT::Site_DB::connect();
$sth = $dbh->prepare (qq{ SELECT * FROM config_settings });
$sth->execute();
my %settings = %{$sth->fetchrow_hashref}; # I'm assuming you only
+ have one row...
foreach my $key (keys %settings) {
my $varname = "$" . $key;
eval "$varname = $settings{$key}"
or die "problem with eval";
}
$sth->finish();
Also, from what you've said, it seems as if you are just using the settings to globally control the properties of HTML text so you only have to change the property in one place. If this is the case, then you should use CSS (Cascading Style Sheets) to define site-wide styles and include the CSS file in every page. CSS is a very powerful mechanism for easily changing the layout and design of a site.
Update: Hmm, I just saw that you want to use the values in the column name as the variable name. The code above uses the name of the field (or column) in MySQL as the variable name. Here is the code to do what you want:
$dbh = CWT::Site_DB::connect();
$sth = $dbh->prepare (qq{ SELECT * FROM config_settings });
$sth->execute();
while (my %settings = %{$sth->fetchrow_hashref};) {
my $varname = "$" . $settings{name};
eval "$varname = '$settings{value}'"
or die "problem with eval";
}
$sth->finish();
That should do the trick, but it is also untested.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|