dropfaith Posted October 7, 2008 Share Posted October 7, 2008 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 More sharing options...
dropfaith Posted October 7, 2008 Author Share Posted October 7, 2008 my mysql table will most likely be like Id Int Auto inc (11) Keyword Varchar (100) Location Varchar (100) Page Varchar (100) Link to comment https://forums.phpfreaks.com/topic/127356-dynamic-keywords/#findComment-658830 Share on other sites More sharing options...
waynew Posted October 7, 2008 Share Posted October 7, 2008 Sorry I'm struggling to understand what you're trying to do exactly. You're wanting keywords displayed on selected areas; defined by the page...? Link to comment https://forums.phpfreaks.com/topic/127356-dynamic-keywords/#findComment-658845 Share on other sites More sharing options...
dropfaith Posted October 7, 2008 Author Share Posted October 7, 2008 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 More sharing options...
Brandon Jaeger Posted October 7, 2008 Share Posted October 7, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.