Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Masterslave's Avatar
    Join Date
    Dec 2005
    Posts
    287
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Display article's title in title tag

    Hi all,

    I want to show the article's title in the title tag.
    But I can't display the title from the article because the title tag is loaded first and the the rest of my page.
    I have a solution with javascript but if you haven't enable javascript, you'll see nothing so I want to do this with PHP, but how.

    Javascript solution:
    Code:
    function synctitle(title)
    {
            document.title = document.title + ' | ' + title;
    }
    PHP Code:
        $title = "    SELECT titel
                    FROM $artikelentable
                    WHERE ID = '" .$_GET['ID'] . "'";
        $showtitle = mysql_query($title) or die (mysql_error());
    ?>
    <body onload="synctitle('<?=mysql_result($showtitle0)?>');">
    This works but I want to make this in PHP.

    My articlepage:
    PHP Code:
    <?
        $query 
    "    SELECT * 
                    FROM $artikelentable 
                    WHERE ID = '" 
    .$_GET['ID'] . "'";
        
    $result mysql_query($query) or die (mysql_error());
    ?>
    <body>
        <div id="content">
            <div class="artikel">
                <? while ($row mysql_fetch_assoc($result))
                    {
    ?>
                        <h1><?=$row['titel'];?></h1>
                        <?=$row['content'];?>
                    <?}?>
            </div>
        </div>
    Does anyone how to achieve this with PHP?
    Thanks in advance!

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    I've only dabbled in PHP/MySQL, but…

    If you perform the db query before the page markup starts to loads, then you can just as easily echo the appropriate row variable directly into the title element as well as using them later in the page's markup.
    Last edited by Bill Posters; 02-08-2006 at 07:56 PM.

  • #3
    Regular Coder Masterslave's Avatar
    Join Date
    Dec 2005
    Posts
    287
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Off course, I'll try that. Stupid me


  •  

    Posting Permissions

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