Jump to content

[SOLVED] creating dynamic meta titles and descriptions with a DB


Recommended Posts

I use mysql to store titles, descriptions and keywords.  My problem now is that I cant get the title, description, and keywords that are loaded into variables passed to the page I want to display the title, description, keywords...

 

I am quite the newbie with php but have some experience with other dev.

 

the reason for this is to duplicate without having to rewrite everything.  Any help is greatly appreciated!

 

 

Simply return the data from the DB as normal.  Then echo this out in the head (so your php has to gpo before this) of your doc.

 

$title = my DB's return

 

 

then in the HTML

 

<title><? echo $title;?></title>

 

etc

etc

I have one page that executes the query then holds the variables,

 

then my index.php page I include the file that executes the query but the variables do not show.....  Not sure, maybe I am missing something?  I can post the code for both pages to help if needed..  thx

this is the main display page

<? include("includes/header.php"); ?>
<BODY onLoad="MM_preloadImages('images/serv1_on.gif','images/serv2_on.gif','images/serv3_on.gif')">
<table width="767" border="0" cellpadding="0" cellspacing="0" align="center">

<!--Top image with logo and contact info-->    

    <tr valign="top">

      <td colspan="3" background="visatep/images/top.jpg" width="767" height="196">

              <div style="position: relative; top: 100px; left: 57px">

                <table border="0" cellpadding="5">

                  <tr valign="top">

                    <td>
                    <img src="visatep/images/logo.gif" width="54" height="82" alt="internet marketing"></td>

                    <td><div class="logo" style="padding-top:10px">blahblah.com</div><div class="slogan">blah blah<p>
                    <font face="Times New Roman">
                    <a href="http://www.blahblah.com/links/">Our Link share directory</a></font></div></td>

                  </tr>

                </table>

              </div>

        <div class="contact">Live Sales and Support<br>
          <img src="visatep/images/phone.gif" alt="internet marketing" width="17" height="12">  1-555-555-8870<span style="FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #0055aa; FONT-FAMILY: Arial">
          </span></div>

      </td>

    </tr>

<!--HMENU-->    

    <tr valign="top">

      <td> </td>

      <td background="visatep/images/hmenu_fill.gif" class="hmenu" width="765" height="26" valign="top" style="padding-top:3px; padding-left:10px">
      <p align="center"><b><font color="#FFFFFF">SITE UNDER CONSTRUCTION</font></b></td>

      <td> </td>

    </tr>

<!--Content rows-->

    <tr valign="top">

      <td colspan="3">

        <table width="100%" border="0" cellpadding="0" cellspacing="0" height="100%">

          <tr valign="top">

            <td width="2" background="visatep/images/left_fill.gif"> </td>

            <td width="762" bgcolor="#F3F3F3">

              <p align="center">
              <span style="FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #0055aa; FONT-FAMILY: Arial">
              <b>
              <a style="COLOR: #0055aa" href="http://www.blahblah.com/links/add_link.php?to=1">
              <font size="5">Click here  >></font></a></b></span></td>

            <td width="3" background="visatep/images/right_fill.gif"> </td>

          </tr>

        </table>

      </td>

    </tr>

  </table>
  <? include("includes/footer.php");?>

this is the header

   <?php include("includes/lib.php");?>
   <?php include("includes/mysql_connect.php");?>
   <?php require_once("title.php");?>
<p align="center"><script type="text/javascript"><!--
google_ad_client = "pub-8696395110467609";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "CC0000";
google_color_bg = "FFFFFF";
google_color_link = "CC0000";
google_color_text = "CC0000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<HTML>

<HEAD>
<?$Page = GetHTTPVar('p');

if($Page == '')
{
$Page = 'home';
$title =  $title;
}
?>
<title><? $title ?></title>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

<meta name="Description" content="<?$description?>">
<meta name="Robots" content="all">

<link href="visatep/custom.css" type="text/css" rel="stylesheet">

<script language="JavaScript" type="text/JavaScript">

<!--

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}



function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}



function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}



function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

//-->

</script>
</HEAD>

  this is the query execute script

<?
include ("includes/mysql_connect.php");





//@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tagdata WHERE tag='im'";
$result=mysql_query($query);


if ($myrow = mysql_fetch_array($result)) {


$title = $myrow["title"];
$description = $myrow["description"];
$keywords = $myrow["keywords"];

  //echo "<table border=1>\n";

  //echo "<tr><td>Title</td><td>Description</td><td>Keywords</td></tr>\n";

// do {

//	printf("<tr><td> %s</td><td>%s</td><td> %s</td></tr>", $title, $description, $keywords);

// } while ($myrow = mysql_fetch_array($result));

//	echo "</table>\n";

} else {

echo "Sorry, no records were found!";	

}



?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.