SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get the right metatags from database, based on loaded page

    Hi all,

    I am really a newbie here, so pleae have patience with me.

    I've got an index page where all my other pages will load. My pages are conected to the database and are getting different records. What i am trying to do, is to load the correct(to be similar with the pages loaded) metatags...title...description,into my index page.

    Can you please give an ideea what to use, or how to do it?

    Thank you!

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,900
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by ryuti View Post
    Hi all,

    I am really a newbie here, so pleae have patience with me.

    I've got an index page where all my other pages will load. My pages are conected to the database and are getting different records. What i am trying to do, is to load the correct(to be similar with the pages loaded) metatags...title...description,into my index page.

    Can you please give an ideea what to use, or how to do it?

    Thank you!
    I have recently coded a hidden session variable on http://johns-jokes.com that
    displays the title, keywords and description for all the pages on my site.

    I have enclosed the following screen-dump:
    http://www.graabr.com/l3E1PX/

    What I do is to get the $title and $description from my database and to use it in my pages:
    PHP Code:
     

    // header
    <head>
    <title><?php echo $title;?></title>
    <meta name='keywords' content='<?php echo $keywords; ?>' />
    <meta name='description' content='<?php echo $description;?>' />
    ...
    ...
    ...
    </head>
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you please show me the script for the session? I want to see if there is any connection to the id from the database.

    The output is relative easy, the association is giving me trouble.

    Thank you!

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,900
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by ryuti View Post
    Can you please show me the script for the session? I want to see if there is any connection to the id from the database.

    The output is relative easy, the association is giving me trouble.

    Thank you!
    I am not sure what you want but here is the code to save_session,php:
    PHP Code:

      
    <?php 

    session_start
    ();

    error_reporting(E_ALL);
    ini_set('display_errors''On');

    if (
    $_POST)
    {
      
    $_SESSION['my_localhost'] = $_POST['my_localhost'];
    }
    ?>

    <form name="input" action="save_session.php" method="post">
        
      <label><?php echo $_SERVER['SERVER_ADDR']; ?></label>
        <input type=ínput' name='my_localhost' value='<?php echo $_SERVER['SERVER_ADDR']; ?>' />
      <input type='submit' name='submit' />

    </form>

    <a href='/'>Johns-Jokes.com</a>
    <br /><br /><br />

    <?php
        
    echo '$_SESSION["my_localhost"] ==> ';
        echo isset(
    $_SESSION['my_localhost']) ? $_SESSION['my_localhost'] : 'Not set';
        
    // $_SESSION['my_localhost'] = 'NOT_SET';
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  5. #5
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry for not explaining to good. I need to learn more english also.

    ok, this is my database(one of the tables):

    `seo` (
    `id` int(255) NOT NULL AUTO_INCREMENT,
    `actor_nume` text COLLATE utf8_unicode_ci NOT NULL,
    `album_nume` text COLLATE utf8_unicode_ci NOT NULL,
    `page_title` text COLLATE utf8_unicode_ci NOT NULL,
    `meta_keywords` text COLLATE utf8_unicode_ci NOT NULL,
    `meta_description` text COLLATE utf8_unicode_ci NOT NULL,
    `image` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
    `alt_tag` text COLLATE utf8_unicode_ci NOT NULL,
    `cloud_tags` text COLLATE utf8_unicode_ci NOT NULL,
    `album_description` text COLLATE utf8_unicode_ci NOT NULL,
    `actor_description` text COLLATE utf8_unicode_ci NOT NULL,
    `h1` text COLLATE utf8_unicode_ci NOT NULL,
    `title` text COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

    my index.php is under root folder

    the pages which will load in index.php are under root/pagini/

    when the pages from root/pagini/ will load in my index.php(under root), i want the information from seo table to be 'echoed' in my index.php, but to be the right data for each record.

    the pages under root/pagini/ have sql queries also, getting different records from the database.

  6. #6
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ryuti View Post
    Sorry for not explaining to good. I need to learn more english also.

    ok, this is my database(one of the tables):

    `seo` (
    `id` int(255) NOT NULL AUTO_INCREMENT,
    `actor_nume` text COLLATE utf8_unicode_ci NOT NULL,
    `album_nume` text COLLATE utf8_unicode_ci NOT NULL,
    `page_title` text COLLATE utf8_unicode_ci NOT NULL,
    `meta_keywords` text COLLATE utf8_unicode_ci NOT NULL,
    `meta_description` text COLLATE utf8_unicode_ci NOT NULL,
    `image` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
    `alt_tag` text COLLATE utf8_unicode_ci NOT NULL,
    `cloud_tags` text COLLATE utf8_unicode_ci NOT NULL,
    `album_description` text COLLATE utf8_unicode_ci NOT NULL,
    `actor_description` text COLLATE utf8_unicode_ci NOT NULL,
    `h1` text COLLATE utf8_unicode_ci NOT NULL,
    `title` text COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;

    my index.php is under root folder

    the pages which will load in index.php are under root/pagini/

    when the pages from root/pagini/ will load in my index.php(under root), i want the information from seo table to be 'echoed' in my index.php, but to be the right data for each record.

    the pages under root/pagini/ have sql queries also, getting different records from the database.


    This is what i did:

    on my included pages under root/pagini/, every page has this code, with different id to get different record from database:


    <?php // this starts the session
    session_start();

    // this sets variables in the session
    $_SESSION['id'] = $_POST['$id'];
    $_SESSION['actor_nume'] = $_POST['$actornume'];
    $_SESSION['album_nume'] = $_POST['$albumnume'];
    $_SESSION['meta_keywords'] = $_POST['$metakey'];
    $_SESSION['page_title'] = $_POST['$pagetitle'];
    $_SESSION['meta_description'] = $_POST['$metadesc'];
    $_SESSION['image'] = $_POST['$image'];
    $_SESSION['alt_tag'] = $_POST['$alttags'];
    $_SESSION['cloud_tags'] = $_POST['$cloudtags'];
    $_SESSION['album_description'] = $_POST['$albumdesc'];
    $_SESSION['actor_description'] = $_POST['$actordesc'];
    $_SESSION['h1'] = $_POST['$h1'];
    $_SESSION['title'] = $_POST['$title'];
    end(); ?>
    <?php
    include ("condb.php");

    $query="SELECT * FROM seo WHERE seo.id=2";
    $result=mysql_query($query);
    $num=mysql_numrows($result);

    mysql_close();
    $i=0;
    while ($i < $num) {

    $id=mysql_result($result,$i,"id");
    $actornume=mysql_result($result,$i,"actor_nume");
    $albumnume=mysql_result($result,$i,"album_nume");
    $pagetitle=mysql_result($result,$i,"page_title");
    $metakey=mysql_result($result,$i,"meta_keywords");
    $metadesc=mysql_result($result,$i,"meta_description");
    $image=mysql_result($result,$i,"image");
    $alttags=mysql_result($result,$i,"alt_tag");
    $cloudtags=mysql_result($result,$i,"cloud_tags");
    $albumdesc=mysql_result($result,$i,"album_description");
    $actordesc=mysql_result($result,$i,"actor_description");
    $h1=mysql_result($result,$i,"h1");



    On my index.php under root i put this code:

    <?php
    // this starts the session
    session_start();
    $_SESSION['id'];
    $_SESSION['actor_nume'];
    $_SESSION['album_nume'];
    $_SESSION['meta_keywords'];
    $_SESSION['page_title'];
    $_SESSION['meta_description'];
    $_SESSION['image'];
    $_SESSION['alt_tag'];
    $_SESSION['cloud_tags'];
    $_SESSION['album_description'];
    $_SESSION['actor_description'];
    $_SESSION['h1'];
    $_SESSION['title'];
    ?>

    When i try to output the file like this:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title><?php print $_SESSION['title']; ?></title>
    <meta name="google-site-verification" content="rm3s8qlIYPX4_gekZXiMewICGfMew66DnKQWOm9NgBQ" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Colectia Mari actori romani. <br> Cand teatrul, muzica si poezia se intalnesc atunci se naste arta. <?php print $_SESSION['meta_description']; ?>">
    <meta name="keywords" content="<?php print $_SESSION['meta_keywords']; ?>">


    the only data showed is this(that is showing correct):
    <title><?php print $_SESSION['title']; ?></title>

    the other ones
    <?php print $_SESSION['meta_description']; ?> and
    <?php print $_SESSION['meta_keywords']; ?>

    are not returning nothing

  7. #7
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,900
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    I am confused with your code but anyway maybe try this:

    Include the following lines of code in index.php
    [PHP]
    <?php
    session_start();
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');

    function check_session($msg='Display session elements')
    {
    echo $msg;
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';
    }

    // test to see the session elements
    check_session('First test');


    Also use the above function before and after loading your session variable from the database.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  8. #8
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    I am confused with your code but anyway maybe try this:

    Include the following lines of code in index.php
    [PHP]
    <?php
    session_start();
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');

    function check_session($msg='Display session elements')
    {
    echo $msg;
    echo '<pre>';
    print_r($_SESSION);
    echo '</pre>';
    }

    // test to see the session elements
    check_session('First test');


    Also use the above function before and after loading your session variable from the database.
    I am confused also , and i know the code is not good, that's why i needed somebody to lightupi my brains.

    This is what i get after putting the code you provided:

    st test

    Array
    (
    [mariactori_arUserLevel] => Array
    (
    )

    [mariactori_arUserLevelPriv] => Array
    (
    )

    [mariactori_status] => login
    [mariactori_SysAdmin] => 1
    [mariactori_status_UserName] => Administrator
    [mariactori_actori_where] =>
    [mariactori_actori_start] => 1
    [mariactori_actori_return] => http://www.mariactoriromani.ro/admin1/actorilist.php
    [mariactori_Message] =>
    [mariactori_album_where] =>
    [mariactori_album_start] => 1
    [mariactori_album_return] => http://www.mariactoriromani.ro/admin1/albumlist.php
    [mariactori_album_continut_where] =>
    [mariactori_album_continut_start] => 1
    [mariactori_album_regie_where] =>
    [mariactori_album_regie_start] => 1
    [mariactori_album_regie_return] => http://www.mariactoriromani.ro/admin1/album_regielist.php
    [mariactori_seo_where] =>
    [mariactori_seo_start] => 1
    [mariactori_seo_return] => http://www.mariactoriromani.ro/admin1/seolist.php
    [id] => 2
    [actor_nume] =>
    [album_nume] =>
    [page_title] =>
    [meta_keywords] =>
    [meta_description] =>
    [image] => imagine test
    [alt_tag] =>
    [cloud_tags] =>
    [album_description] =>
    [actor_description] =>
    [h1] => h1 test
    [title] => titlu test
    )


    the index.php
    http://www.mariactoriromani.ro/index1.php

    the testing page here
    http://www.mariactoriromani.ro/index1.php?pg=pagina_test

  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,900
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    I tried one of the links you gave, highlighted the page and the following errors were displayed:


    PHP Code:
    First test

    Array
    (
    )


    NoticeUndefined indexid in /home/mari/public_html/index1.php on line 18

    Notice
    Undefined indexactor_nume in /home/mari/public_html/index1.php on line 19

    Notice
    Undefined indexalbum_nume in /home/mari/public_html/index1.php on line 20

    Notice
    Undefined indexmeta_keywords in /home/mari/public_html/index1.php on line 21

    Notice
    Undefined indexpage_title in /home/mari/public_html/index1.php on line 22

    Notice
    Undefined indexmeta_description in /home/mari/public_html/index1.php on line 23

    Notice
    Undefined indeximage in /home/mari/public_html/index1.php on line 24

    Notice
    Undefined indexalt_tag in /home/mari/public_html/index1.php on line 25

    Notice
    Undefined indexcloud_tags in /home/mari/public_html/index1.php on line 26

    Notice
    Undefined indexalbum_description in /home/mari/public_html/index1.php on line 27

    Notice
    Undefined indexactor_description in /home/mari/public_html/index1.php on line 28

    Notice
    Undefined indexh1 in /home/mari/public_html/index1.php on line 29

    Notice
    Undefined indextitle in /home/mari/public_html/index1.php on line 30 
    These errors need to be fixed.

    I am off to bed and hopefully another poster can provide a solution.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  10. #10
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    I tried one of the links you gave, highlighted the page and the following errors were displayed:


    PHP Code:
    First test

    Array
    (
    )


    NoticeUndefined indexid in /home/mari/public_html/index1.php on line 18

    Notice
    Undefined indexactor_nume in /home/mari/public_html/index1.php on line 19

    Notice
    Undefined indexalbum_nume in /home/mari/public_html/index1.php on line 20

    Notice
    Undefined indexmeta_keywords in /home/mari/public_html/index1.php on line 21

    Notice
    Undefined indexpage_title in /home/mari/public_html/index1.php on line 22

    Notice
    Undefined indexmeta_description in /home/mari/public_html/index1.php on line 23

    Notice
    Undefined indeximage in /home/mari/public_html/index1.php on line 24

    Notice
    Undefined indexalt_tag in /home/mari/public_html/index1.php on line 25

    Notice
    Undefined indexcloud_tags in /home/mari/public_html/index1.php on line 26

    Notice
    Undefined indexalbum_description in /home/mari/public_html/index1.php on line 27

    Notice
    Undefined indexactor_description in /home/mari/public_html/index1.php on line 28

    Notice
    Undefined indexh1 in /home/mari/public_html/index1.php on line 29

    Notice
    Undefined indextitle in /home/mari/public_html/index1.php on line 30 
    These errors need to be fixed.

    I am off to bed and hopefully another poster can provide a solution.
    ok, i will try to see what is the problem.
    thank you for your time.


Bookmarks

Posting Permissions

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