Jump to content

Display META TAGS with PHP


gotry

Recommended Posts

Hi,

 

I am doing SEO work for a website made with PHP and MySQL. The website is divided into 8 categories with different theme and I would be interested to target different keywords and meta descriptions for each category, but there is only one index.php. Each category has an ID (from 1 to 8). The IDs, names of the categories and targets are in a table called t_cats.

The name of the ID field is catid, the categories field name is catname, and fields of the META TAGS are META_KEYWORDS and META_DESCRIPTION.

 

The php code I put in the header of index.php is

 

<?php 

$query = mysql_query("SELECT META_KEYWORDS FROM t_cats where ID='1';"); 

while($array=mysql_fetch_row($query)){

echo $array[0];

}

?> 

 

and actually shows me the keywords and descriptions of the first category to all categories. If I change the number 1 for any of the IDs, displays the METAs of the category with that ID.

What code I have to put to change automatically the number of the IDs?

Link to comment
https://forums.phpfreaks.com/topic/184476-display-meta-tags-with-php/
Share on other sites

There will post likely be a $_GET variable where the id is held. If you go to one of these category's page's, you should see the id in the url with the name of the variable to the left of it. Something like "catid=1." In this case, the $_GET variable would be $_GET['catid']. Once you have found what that variable is named, you can use it in place of the static number in your query:

<?php 

$query = mysql_query("SELECT META_KEYWORDS FROM t_cats where ID='".$_GET['catid']."';"); 

while($array=mysql_fetch_row($query)){

echo $array[0];

}

?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.