Search the Community
Showing results for tags 'metadata'.
-
I have a basic MySQL database setup holding relevant meta information for a few pages, starting small, I want the meta information to load dynamically depending on the page that the user is viewing. I have the connection script working fine, I have echoed the data out via variables and everything is looking good however I am now at the stage where I want to echo that data out on the page in the relevant fields but cannot seem to get it working. So far I have <?php include 'connect.php'; $title = 'page_title'; $pname = 'page_name'; $desc = 'meta_description'; $key = 'meta_keywords'; $aut = 'author'; $copyr = 'copyright'; $email = 'email'; $rating = 'rating'; $robots = 'robots'; $visit = 'revisit'; $exp = 'expires'; $dist = 'distribution'; $query = $db->query("SELECT * FROM meta_data"); while ($row = $query->fetch(PDO::FETCH_ASSOC)){ echo $row[$pname] . '<br>'; echo $row[$title]. '<br>'; echo $row[$desc]. '<br>'; echo $row[$key]. '<br>'; echo $row[$aut]. '<br>'; echo $row[$copyr]. '<br>'; echo $row[$email]. '<br>'; echo $row[$rating]. '<br>'; echo $row[$robots]. '<br>'; echo $row[$visit]. '<br>'; echo $row[$exp]. '<br>'; } ?> The while loop was just testing that I was getting the data, it echoes out fine, although I do get every page in the DBase. I then have <link rel="apple-touch-icon" href="apple_touch_icon.png"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="description" content="<?php echo $desc; ?>" /> <meta name="keywords" content="<?php echo $key; ?>" /> <meta name="copyright" content="<?php echo $copyr; ?>" /> <meta name="author" content="<?php echo $aut; ?>" /> <meta name="email" content="<?php echo $email; ?>" /> <meta name="Distribution" content="<?php echo $dist; ?>" /> <meta name="Rating" content="<?php echo $rating; ?>" /> <meta name="Robots" content="<?php echo $robots; ?>" /> <meta name="Revisit-after" content="<?php echo $visit; ?>" /> <meta name="expires" content="<?php echo $exp; ?>" /> <link rel="shortcut icon" href="favicon.ico" type="image/icon" /> <!-- favicon for browser, the image is .ico file in root directory--> <title><?php echo $title; ?></title> As it stands at the moment all I get in the page fields is the database field name but as I say I get the data from the database when echoing the row. Could someone advise me where I am going wrong and steer me in the right direction to get the appropriate data for the page in question? Thanks for any help.selectdata.phphome.php