所以我有更多的查询包含从$keywords
获取的值,当我调用stmt->fetch()
我的表有一些结构(colums)时没有出现,所以我尝试搜索关键字(列)然后显示查询哪个titlu(列)包含特定关键字($keywords
),但即使我在关键字列值顶部其他查询中有一个例子,也不会显示任何内容在列关键字值顶部
$stmt = $con->prepare('SELECT keywords FROM stiinta WHERE link = ? LIMIT 1');
$stmt->bind_param('s', $pageid);
$stmt->execute();
$stmt->bind_result($keyword);//variabla pe care o vrei inlocuita prin bind_Result in loc de get_Result
while ($stmt->fetch()) {
$keyword; // faci acelasi lucru fara $row
}
$stmt->close();
测试
$stmt = $con->prepare("SELECT id, titlu, link, poza, alt, keywords, linknews FROM stiinta WHERE approved='1' AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE ? UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM travel WHERE approved='1' AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE ? UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM stiinta WHERE approved='1' AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE ? UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM natura WHERE approved='1' AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE ? UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM lifestyle WHERE approved='1' AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE ? LIMIT 10");
$stmt->bind_param("sssss", $keyword, $keyword, $keyword, $keyword, $keyword);
$stmt->execute();
if(!$stmt->execute()){
echo "a aparut o eroare";}
$stmt->bind_result($id, $titluKEY, $linkKEY, $pozaKEY, $altKEY, $keywordKEY, $linknewsKEY);//variabla pe care o vrei inlocuita prin bind_Result in loc de get_Result
$stmt->store_result();
if ($stmt->num_rows == 0) {// verificare daca este vrun query
echo "You did not have any queries to match.<br>";
} else {
$stiintalist = '';
while ($stmt->fetch()) {
$id;
$titluKEY;
$linkKEY;
$pozaKEY;
$altKEY;
$keywordKEY;
$linknewsKEY; // 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.'"
$stiintalist .= '<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>';
}
}
$stmt->free_result();
$stmt->close();
echo $stiintalist;
告诉我您没有任何匹配的查询,这意味着$stmt->num_rows == 0
为空,即使我在其他查询中有一些单词....
答案 0 :(得分:0)
可能是你的列是char类型然后尝试添加wildchar
$stmt = $con->prepare("
SELECT id, titlu, link, poza, alt, keywords, linknews
FROM stiinta
WHERE approved='1'
AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%')
UNION
SELECT id, titlu, link, poza, alt, keywords, linknews
FROM travel
WHERE approved='1'
AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%')
UNION
SELECT id, titlu, link, poza, alt, keywords, linknews
FROM stiinta
WHERE approved='1'
AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%')
UNION
SELECT id, titlu, link, poza, alt, keywords, linknews
FROM natura
WHERE approved='1'
AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%')
UNION
SELECT id, titlu, link, poza, alt, keywords, linknews
FROM lifestyle
WHERE approved='1'
AND replace(replace(replace(titlu, ',', ''), '-', ''), ' ', '') LIKE concat('%', ? , '%')
LIMIT 10
");
答案 1 :(得分:0)
由于您的$pageid
可能是整数(?),您可以尝试将第二行更改为
$stmt->bind_param('i', $pageid);