richclever
IS-IT--Management
I am really confused.
I have a set of database fields that have a list of keywords in them that are comma delimited.
I have read them into an array and exploded them so each keyword is in a seperate array element; thus I have the follwing list in my array from one record:
$arr1[1]="potato"
$arr1[2]="potatoes"
$arr1[3]="garden"
The second record is read into a different array $arr2 and contains the following elements:
$arr2[1]="gardening"
$arr2[2]="plants"
$arr2[3]="new potatoes"
$arr2[4]="varieties of pôtatoes"
What I need to do, is have the first array $arr1 look through the second array $arr2 and if there are 2 or more similar entries, display the second array. So, $arr1 compared to $arr2 will find 5 similarities or exact matches and so output the entries in $arr2.
Does any one have anyideas. I have tried to use strist to compare them but for some reason it is not working.
I enclose my php if anyone is interested (you will see that it actually constructs a menu that is defined elsewhere)
<?php
include ("authormenu.inc");
if ($pagekeywords != ''){
//relevant menu
$relevantmenu=$relevant_menu_header;
$relevantcount=0;
//picks keywords from article and places them in an array. compares other articles keywords with current article and flags any relevances.
$arr1=explode(',', $pagekeywords);
$arr1length = count ($arr1);
for ($l1 = 0; $l1 < $arr1length; $l1++){
//echo "$arr1[$l1] ,";
$relevantquery="SELECT title, author, pid, uid, keywords FROM pages WHERE keywords LIKE '$arr1[$l1]'";
$relevantresult=mysql_query($relevantquery);
while (list($title, $author,$pid, $uid, $keywords) = mysql_fetch_row($relevantresult)){
$arr2=explode (',', $keywords);
$arrayLength = count($arr2);
if ($pid != $sectionuid){
if ($author != $pageauthor){
for ($i = 0; $i < $arrayLength; $i++){
for ($i1 = 0; $i1 < $arr1length; $i1++){
if (stristr($arr1[$i1], $arr2[$i])){
$relevantmenu=$relevantmenu . $relevant_menu_link1 . $uid . $relevant_menu_link2 . $title . $relevant_menu_link3;
$relevantcount++;
if ($relevantcount =1){
$menucount++;
//$relevantcount = 0;
};
};
};
};
};
};
if ($menucount>1){
$relevantmenu=$relevantmenu . $relevant_menu_link1 . $uid . $relevant_menu_link2 . $title . $relevant_menu_link3;
//$menucount=0;
};
};
};
};
$relevantmenu=$relevantmenu . $relevant_menu_footer;
?>
Thanks Rich
I have a set of database fields that have a list of keywords in them that are comma delimited.
I have read them into an array and exploded them so each keyword is in a seperate array element; thus I have the follwing list in my array from one record:
$arr1[1]="potato"
$arr1[2]="potatoes"
$arr1[3]="garden"
The second record is read into a different array $arr2 and contains the following elements:
$arr2[1]="gardening"
$arr2[2]="plants"
$arr2[3]="new potatoes"
$arr2[4]="varieties of pôtatoes"
What I need to do, is have the first array $arr1 look through the second array $arr2 and if there are 2 or more similar entries, display the second array. So, $arr1 compared to $arr2 will find 5 similarities or exact matches and so output the entries in $arr2.
Does any one have anyideas. I have tried to use strist to compare them but for some reason it is not working.
I enclose my php if anyone is interested (you will see that it actually constructs a menu that is defined elsewhere)
<?php
include ("authormenu.inc");
if ($pagekeywords != ''){
//relevant menu
$relevantmenu=$relevant_menu_header;
$relevantcount=0;
//picks keywords from article and places them in an array. compares other articles keywords with current article and flags any relevances.
$arr1=explode(',', $pagekeywords);
$arr1length = count ($arr1);
for ($l1 = 0; $l1 < $arr1length; $l1++){
//echo "$arr1[$l1] ,";
$relevantquery="SELECT title, author, pid, uid, keywords FROM pages WHERE keywords LIKE '$arr1[$l1]'";
$relevantresult=mysql_query($relevantquery);
while (list($title, $author,$pid, $uid, $keywords) = mysql_fetch_row($relevantresult)){
$arr2=explode (',', $keywords);
$arrayLength = count($arr2);
if ($pid != $sectionuid){
if ($author != $pageauthor){
for ($i = 0; $i < $arrayLength; $i++){
for ($i1 = 0; $i1 < $arr1length; $i1++){
if (stristr($arr1[$i1], $arr2[$i])){
$relevantmenu=$relevantmenu . $relevant_menu_link1 . $uid . $relevant_menu_link2 . $title . $relevant_menu_link3;
$relevantcount++;
if ($relevantcount =1){
$menucount++;
//$relevantcount = 0;
};
};
};
};
};
};
if ($menucount>1){
$relevantmenu=$relevantmenu . $relevant_menu_link1 . $uid . $relevant_menu_link2 . $title . $relevant_menu_link3;
//$menucount=0;
};
};
};
};
$relevantmenu=$relevantmenu . $relevant_menu_footer;
?>
Thanks Rich