Announcement

Collapse
No announcement yet.

Installing templates with $var in MySQL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Installing templates with $var in MySQL

    I know vB installs its templates with $var type variables in it. However, I cannot get the install script for a little news program I wrote to install $var type variables into the database.

    When I set my database query to insert the templates, it's like:
    PHP Code:
    $sql "INSERT INTO ashnews_templates VALUES ('', 
            '<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\r\n<tr>\r\n<td class=\"title\">
    $title</td>\r\n</tr>\r\n<tr>\r\n<td class=\"text\">$text</td>\r\n</tr>\r\n$displayattach\r\n<tr>\r\n<td class=\"comments\" align=\"right\">Posted by <a href=\"mailto:$email\">$name</a> on $date $comments</td>\r\n</tr>\r\n</table><br>')"
    I know why they don't get installed...because using this method all the variables are null and are interpreted as their value of null.

    How do I get the $var type variables into the database like vB does?

    Hope this made sense!
    Last edited by sccr410; Thu 11 Apr '02, 9:31pm.

  • #2
    vB doesnt do that, vB stores the posts seperately, and puts them into the template when the post is requested.

    that way you are able to update the template and it will apply to everything.

    becoz im not as gud at programing as the vB guys, i simply use stuff like

    <% title %>

    then using replace, and the which function, it just replaces the title into each post.

    Comment


    • #3
      It is because you have $title right there in your assignment so it is being evaluated. If you don't want it evaluated you can escape the $ or enclose the string with apostrophes, i.e.

      Apostrophes stop variable evaluation but you have to escape any that appear in the string:
      $sql = 'INSERT INTO table (text) VALUES (\'$table\')';

      Quotes allow variable evaluation unless you escape the $ on the variable name.
      $sql = "INSERT INTO table (text) VALUES ('\$table')';

      If I am understanding your question correctly. You are trying to insert some text that contains variables to serve as your template. At some point you retrieve this text and then eval() it to set the variables that you saved in the text. Yeah?

      Comment


      • #4
        i assumed he meant puttin the variables into the template and storing the template with the post inside the database.

        Comment


        • #5
          Yep, freddie hit it. Thanks a bunch, this will make things much better

          Comment

          Related Topics

          Collapse

          Working...
          X