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 6 of 6

Thread: PHP Titles?

  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Titles?

    Hi all,

    I have a page, where named example.php?id=5 then the code will retrieve the rows from id 5, which then the rest of the code puts them out. For example, id 5 may be the person John and then id 4 may be Jane.

    The mysql retrieving works when i try to display the info. However, is it possible to use these to set my <title></title>?
    I've tried many ways,
    PHP Code:
    <?php echo htmlspecialchars($retrieverowENT_QUOTES'utf-8');?>
    where $retrieverow was set at the bottom of the page(someone told me so) and others like $_GET. However, the title still remained blank.

    Is there a solution to this? Many thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Did you put it between your <title> elements?
    You can do this of course. It simply means restructuring so your processing ends up before your HTML output. Ultimately this is what you should do in PHP anyways.
    A really simple example:
    PHP Code:
    <?php

    // Do whatever to get these records.  I'll just pretend that I have a function for it.
    $record fetchMaRecord($_GET['id']);
    // now $record has what it need, and presumably only one result.
    ?>
    <Doctype. . .>
    <html>
        <head>
            <title><?php echo $record['name'];?></title>
        </head>
        <body>
    ....
    Simple as that. Just make sure that you don't output the head and title until after you've retrieved your results.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Yes, I have put it between <title>. However, it still doesn't work.
    I've tried something similar to your suggestions before. However, nothing still appears. Does it matter of I am using PDO to connect to the database?

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    can you post what you have now?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Arcticwarrio and Fou-Lu,

    Thanks a bunch for attempting to help, but I've solved it myself by simply moving this
    PHP Code:
    foreach ($sql as $row
    statement at the top of the page, and everything worked.

    Many thanks!

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    if you find the first row from each query missing you can reset it without a new query too:

    PHP Code:

    db
    ('open'); 
    $Results query("SELECT * FROM table");
    db('close');

    while (
    $Row mysql_fetch_array($Results)) {

    //script

    }

    mysql_data_seek($Results0); // resets the query back to the first row

    while ($Row mysql_fetch_array($Results)) {

    //another script


    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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