MySQL issue displaying on a page

Discussion in 'PHP' started by stupidfly, May 29, 2007.

  1. #1
    I have some info in a MySQL database. One of the columns is called "tags" and I want to put its contents in a meta keyword tag in the header. I am displaying other info from the database, but I can't get it to display in the header.

    Each page looks roughly like this...
    include header.php
    Page content
    include footer.php

    My SQL query looks something like 'SELECT * FROM tablename WHERE id='.$id

    Content is then being placed into the page. The issue is that I can't get the tags to display in the header (which is a different file)

    I hope you can understand this. Thanks for the help.
     
    stupidfly, May 29, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    is there an error message? add some 'or die()' statements to your code.
    ans also please see this site: parseerror.com/~pizza/select*isevil.html
     
    ansi, May 29, 2007 IP
  3. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I do not have an 'or die()' statement on there, I'll try that later today when I get a minute.

    Thanks
     
    stupidfly, May 30, 2007 IP
  4. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I did some tests to try to fix the problem. I don't think my issue is with the MySQL database.

    If I have an index.php file with this coding...
    <? $title="Index.php title"; ?>
    <? include 'http://mysite.com/header.php'; ?>
    index.php contents
    </body>
    </html>
    
    Code (markup):
    and my header looks like...
    <html>
    <head>
    <title><? print $title; ?></title>
    </head
    <body>
    Code (markup):
    Nothing is displayed in the title. I have done this on other sites, and I can't figure out why it won't now.
     
    stupidfly, May 30, 2007 IP
  5. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #5


    When you specify a URL as the include path the PHP code is processed on the server where you are pointing to, in it's own variable scope. Its as if you typed http://mysite.com/header.php into your browser, the header.php is executed on it's own.

    If, for some strange reason, you must use a remote URL like that you can pass variables to it like regular GET parameters:

    <? include 'http://mysite.com/header.php?title=helloworld'; ?>

    Then in the header.php you would have to grab it from $_GET['title']


    I hope that helps :)
     
    mrmonster, May 30, 2007 IP
    stupidfly likes this.
  6. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It did help. The reason it worked for me in the past was that I normally used <? include ($_SERVER['DOCUMENT_ROOT'].'/header.php'; ?>
    Once I switched it, it worked perfect. Thanks for the help.
     
    stupidfly, May 30, 2007 IP