SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing variables within DB?

    lets say I have two tables in my DB, settings, and main.
    in the settings table, it has some settings, duh, like bgcolor1, bgcolor2, etc.
    now, in main, I put certain things that I want output onto my site, like the main nav table that goes on the left. in that table, I want to use some of the settings, like bgcolor1.
    how do I get the output file to parse the contents of the main DB so that it uses the value of bgcolor1, instead of printing "bgcolor1"?

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you'll want to have all variables set (for example, a query to make sure all variables, IE "bgcolor", or whatever you might be using, are available to the script). After that, you should be able to use PHP's eval() function to parse the variables inside the templates. Check it out.

    http://www.php.net/eval

    Good luck.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick reply, checking it out now

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks dude, works like a charm

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, maybe not like a charm, exactly
    what do you mean by
    I think you'll want to have all variables set (for example, a query to make sure all variables, IE "bgcolor", or whatever you might be using, are available to the script).
    ?

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I have this:
    PHP Code:
    $settings mysql_query("SELECT * FROM tq_settings") or die ("Error:".mysql_error());
    $settings_row mysql_fetch_array($settings); 
    ok, I think I know what I'm gonna do now

  7. #7
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $settings = mysql_query("SELECT * FROM tq_settings") or die ("Error:".mysql_error());
    $settings_row = mysql_fetch_array($settings);
    Hmm...I don't understand. What's that table look like? You see, you'll need to use a function, like extract() to automatically create all the necessary variables.

  8. #8
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, I see, I'll look into it tonight, thanks
    I was just making $settings_row global and using it like that, $settings_row["bgcolor1"], but I was gonna do it another way anyway, but this looks better

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, so far it works fine, but now I'm trying to create an edit page. what I want is to put the contents of the "contents" field into a textarea so it can be edited. here is the code I have
    PHP Code:
    $contents stripslashes($blocks_row["contents"]); 
    and then later
    PHP Code:
    <textarea cols="80" rows="20" name="contents" value="<?php echo $contents?>"></textarea>
    here is what is in the table
    PHP Code:
    <tr bgcolor=\"$bgcolor3\"><td nowrap>test</td></tr> 
    but this is what gets outputted
    PHP Code:
    <TEXTAREA cols=80 name=contents rows=20 $bgcolor3value="<tr bgcolor=">&lt;td nowrap&gt;test&lt;/td&gt;&lt;/tr&gt;"&gt;</TEXTAREA> 

  10. #10
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind, stupid mistake


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •