I made a loop which take from a value e.g. #test #top #travel
(from a variable) and split in each array to show me all the results which match with the keyword, but the query show me only the results for the last key e.g #travel
and I want to show for each key the query which match with the statement. Sorry if is a easy question, but I really search and nothing...
//the loop
$keywordArray = explode(' ', $keyword);
foreach ($keywordArray as $keywordArrayGo) {
echo $keywordArrayGo;
$sqlKeywordArray = "SELECT id, titlu, link, poza, alt, keywords, linknews FROM stiinta WHERE approved='1' AND replace(replace(replace(keywords, ',', ''), '-', ' '), ' ', '') LIKE concat('%', ? , '%') UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM travel WHERE approved='1' AND replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%') UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM natura WHERE approved='1' AND replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%') UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM travel WHERE approved='1' AND replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%') UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM lifestyle WHERE approved='1' AND replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%') LIMIT 10";
the prepare stmt
$stmt = $con->prepare($sqlKeywordArray);
$stmt->bind_param("sssss", $keywordArrayGo, $keywordArrayGo, $keywordArrayGo, $keywordArrayGo, $keywordArrayGo);
$stmt->execute();
check the results for each key.
$stmt->store_result();
/* Get the number of rows */
$checkQuery = $stmt->num_rows;
echo "$keywordArrayGo : $checkQuery : QUERY care sa se potriveasca <br>";
if ($checkQuery == 0) {// verificare daca este vrun query
echo "<FONT color='red'><strong>NU SE POTRIVESTE NICIO INREGISTRARE.</strong><br></font>";
}
the $checkQuery
for the value e.g. (#top #test #travel
) is (10 2 4
)
and show results which match with the key split using explode()
$stmt->bind_result($idSearch, $titluKEY, $linkKEY, $pozaKEY, $altKEY, $keywordKEY, $linknewsKEY);//variabla pe care o vrei inlocuita prin bind_Result in loc de get_Result
$keywordArticleMatch ="";
while ($stmt->fetch()) {
// faci acelasi lucru fara $row trb sa fie in concordanta cu ceea ce este in SELECT column pentretu teste a href="/page-stiinta.php?pid='.$linkKEY.'"
$keywordArticleMatch .= '<div id="articol-content-more"><a href="/'.$linknewsKEY.'"><img src="/images/'.$pozaKEY.'.jpg"class="articol-content-more-image" alt="'.$altKEY.'"><p class="articol-content-more-title">'.$titluKEY.'</p></a><span><a class="articol-content-more-afla" href="/'.$linknewsKEY.'">Citește mai multe</a></span><span class="articol-content-more-fl"><div class="fb-share-button" data-layout="button_count" data-href="http://esticurios.ro/'.$linknewsKEY.'"></div></span></div><br>';
}
/* free results */
$stmt->free_result();
$stmt->close();
} //close the loop
And the problem is showing me only the results of the last key from the value AND i want to make this to show for the all key, not only from the last key splited