Jump to content

Dynamic Keywords


dropfaith

Recommended Posts

So im writing a script to change out my keywords faster on all pages using a database.

 

problem is  i have two fields i wnt specified and a limit of 20 keywords so say theres 13 results for the page title of rideshare i want it to then fill the remaining 7 keyword slots with location based keywords

 

i know the use of where will be required but im not sure how to set it to pull all with page then if it runs out before the limit of 20 to choose a different selector?

hopefully this makes sense

 

$query = "SELECT * FROM Keywords WHERE Page = '$Page' or Location=$location";

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

 

// Loop thru keywords ill build here then display

 

<meta name="keywords" content="<? echo $row->Pagekeyword; ?>, or location if page keyowrds dont exist or fill limit " />

 

 

Link to comment
https://forums.phpfreaks.com/topic/127356-dynamic-keywords/
Share on other sites

okay take http://lawrenceguide.org/restuarant/delivery.php for example

 

i want all keywords pertaining to restaurants  but if there isnt 20 results for resturants  i want it to pull the remaining slots  from Location

 

 

so say these keywords hit resturants

 

food, delivery, pizza ,chinese, mexican,

then these are for the location

Lawrence ks ,66044, kansas ,

below would result the first set for the restuarant keywords.

what im trying to do is to also then include the ones for location due to there not being the max amount of 20

 

$query = "SELECT * FROM Keywords WHERE Page = '$Page'"; 

$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/127356-dynamic-keywords/#findComment-658856
Share on other sites

Here's my attempt:

$keyword_limit = 20;

$location_query = "SELECT * FROM Keywords WHERE Location='$location' LIMIT $keyword_limit";
$location_result = mysql_query($location_query) or die ("Error in query: $location_query. " . mysql_error());

$loc_keyword_total = mysql_num_rows($location_result);
$loc_keyword_extras = $keyword_limit - $loc_keyword_total;

$extra_page_query = "SELECT * FROM Keywords WHERE Page='$page' ORDER BY rand() LIMIT $keyword_extras";
$extra_page_result = mysql_query($extra_page_query) or die ("Error in query: $extra_page_query. " . mysql_error());

$keyword_extras_num = 1;
$keyword_extras = '';

while($row = mysql_fetch_assoc($extra_page_result))
{
if($keyword_extras_num < $loc_keyword_extras)
	$delimeter = ', ';

$keyword_extras .= $row["Keyword"] . $delimeter;

$keyword_extras_num++;
}

$keywords_final_num = 1;
$keywords_final = '';

while($row = mysql_fetch_assoc($location_result))
{
if($keyword_final_num < $loc_keyword_total)
	$delimeter = ', ';

$keywords_final .= $row["Keyword"] . $delimeter;

$keywords_final_num++;
}

$extras = !empty($keywords_extra) ? ', ' : '';

$keywords_final .= $extras . $keyword_extras;

<meta name="keywords" content="<? echo $keywords_final; ?>, or location if page keyowrds dont exist or fill limit " />

 

You may have to edit some parts to suit your needs.

Link to comment
https://forums.phpfreaks.com/topic/127356-dynamic-keywords/#findComment-658861
Share on other sites

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.