I have got the following code to find the similar keywords in body of a text and display the related links with same keyword.
But the problem is for example if two keywords are in row 2 body, Row 2 displays two times but I need the row 2 is displayed once. I tried SELECT DISTINCT but it does not work in foreach loop correctly.
$tags2=explode(",",$tags);
foreach ($tags2 as $i) {
$cat_sqlii="SELECT DISTINCT id, source,title,summary,newsText,photo,mainphoto,link,Date,tags FROM newxtext WHERE (newsText LIKE '%$i%')";
$cat_sql_queryii=mysqli_query($con,$cat_sqlii);
$cat_sql_rowii=mysqli_fetch_assoc($cat_sql_queryii);
do{
echo $cat_sql_rowii['id'].'<br/>';
}while($cat_sql_rowii=mysqli_fetch_assoc($cat_sql_queryii));
}
distinctonly works for the concurrent query. in your foreach loop, you issue one query for each keyword. these queries don't know about each other. I recommend working with a temporary table receiving the result and then querying this table usingdistinct.