Help making a query into a variable for php template

Discussion in 'PHP' started by jgjg, Sep 4, 2008.

  1. #1
    Lets say I want to use a php template and my current method is something like:

    Step 1: Set variables

    $titletag = "page title";
    $h1tag = "welcome to my site";
    $content = "blah blah blahdedy blah blah blah";

    Step 2: Include a template with variables that are replaced
    <?php require_once('../template.php'); ?>

    This is all fine and good with simple content...But how do I do this if there are sql queries with lots of quotation marks in my $content? How can I make a big page full of sql queries and other word into the $content variable so that I can use it with my template?

    I had some success making other pages (like webforms) into $content because I could replace all of the " characters with '. However, sql queries seem to need " characters.
     
    jgjg, Sep 4, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SQL queries don't need " actually. When specifying a string value in SQL, use single quotations. If you still need double quotations, simply escape it with \"
     
    JAY6390, Sep 4, 2008 IP
  3. jgjg

    jgjg Peon

    Messages:
    595
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3


    the queries are not in the template...they are above the template in the code.

    however lets say I want to create a variable $content

    if the variable $content has the sql queries in it and a lot of other information, it seems like it has to use " at some point...

    It's like having to include a whole page of content into the $content variable and not being able to use " anywhere as that would make the code badly formed and cause errors

    example:

    <?php
    $db = mysql_select_db($database,$connection)
    or die ("couldn't select database");
    $query = "select * from table1 where state='$state'";
    $result = mysql_query($query)
    or die ("couldn't do query");
    ?>

    how could I make that into part of the variable $content ???
     
    jgjg, Sep 5, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    hmm, you aren't making much sense with this. From what I can gather however, you need to use the eval() function
     
    JAY6390, Sep 6, 2008 IP