Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    I was wondering if anyone knows how to add unique metatag data (keywords, page description, title) to each page from a database using php. The rest of the page is populated from a database but I just can't figure out how to add the meta information. The code that I have come up with is as follows

    Code:
    <?php
        $subject_set = mysql_query("Select * FROM movies WHERE title like '%".$info."%' and media = '".$med."'", $connection);
            if (!$subject_set){
                die("Database selection failed: " . mysql_error());}
    
        while ($row    = mysql_fetch_array($subject_set)){
    
    $pgKeywords = $_GET['keywords'];
    $pgDesc = $_GET['page_description'];
    $tpTitle = $_GET['title'];?>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="<?php echo $pgKeywords?>">
    <meta name="description" content="<?php echo $pgDesc?>">
    <meta name="title" content="<?php echo $tpTitle?> Review on MRZ">
    <title><?php echo $tpTitle?> Review on MRZ</title>
    <?php } ?>
    I have tried a few different approaches but with no success. Any help would be appricated, thanks.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,724
    Member #
    5580
    Liked
    718 times
    PHP Code:

    <?php
        $subject_set 
    mysql_query("Select * FROM movies WHERE title like '%".$info."%' and media = '".$med."'"$connection);
            if (!
    $subject_set){
                die(
    "Database selection failed: " mysql_error());}
    // I'm assuming your MySQL query will only return one row.
    // If your result is several rows, the variables you are
    // using will be set to the values of the last result found.
    while ($row    mysql_fetch_array($subject_set)){
    $pgKeywords $row['keywords'];
    $pgDesc $row['page_description'];
    $tpTitle $row['title'];
    }
    ?>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="<?php echo $pgKeywords?>">
    <meta name="description" content="<?php echo $pgDesc?>">
    <meta name="title" content="<?php echo $tpTitle?> Review on MRZ">
    <title><?php echo $tpTitle?> Review on MRZ</title>
    John Mc Grath likes this.


  4. #3
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    Thanks for that help miseim. I feel very stupid for not spotting those changes you made but I am only a novice at php. I was trying to fix this problem for a while and have modified my code so many times. Even when I made the changes you posted it still didn't work but I found the problem which was to do with the field in the database. Once again thank you for your help.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:48 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com