Nasıl html etiketi de dahil olmak üzere ilk 500 karakteri değil, arayabilirim?
Aşağıda bir metin oluşan bir anahtar kelime arıyor ki, bugüne kadar birlikte gündeme geldi
SELECT *
FROM root_pages
WHERE root_pages.pg_cat_id = '2'
AND root_pages.parent_id != root_pages.pg_id
AND root_pages.pg_hide != '1'
AND root_pages.pg_url != 'cms'
AND root_pages.pg_content_1 REGEXP '[[:<:]]".$search."[[:>:]]'
OR root_pages.pg_content_2 REGEXP '[[:<:]]".$search."[[:>:]]'
ORDER BY root_pages.pg_created DESC
Nasıl içine daha fazla koşul ekleyebilirsiniz - html etiketi yer kalmamasıdır 500 mektuplar ilk kez?
Mümkündür - bu ilk paragrafta yalnızca anahtar kelime arama yapabilirsiniz eğer mükemmel olurdu?
edit:
yardım çocuklar için teşekkürler! Bu benim çözümdür:
# query to search for “whole word match” in SQL only, e.g. when I search for "rid", it should not match "arid", but it should match "a rid".
# you can use REGEXP and the [[:<:]] and [[:>:]] word-boundary markers:
$sql = "
SELECT *
FROM root_pages
WHERE root_pages.pg_cat_id = '2'
AND root_pages.parent_id != root_pages.pg_id
AND root_pages.pg_hide != '1'
AND root_pages.pg_url != 'cms'
AND root_pages.pg_content_1 REGEXP '[[:<:]]".$search."[[:>:]]'
OR root_pages.pg_content_2 REGEXP '[[:<:]]".$search."[[:>:]]'
ORDER BY root_pages.pg_created DESC
";
# use the instantiated db connection object from the init.php, to process the query
$items = $connection -> fetch_all($sql);
$total_item = $connection -> num_rows($sql);
if ($total_item > 0)
{
foreach($items as $item)
{
# get the content
if(empty($item['pg_content_2'])) $pg_content = strip_tags($item['pg_content_1']);
else $pg_content = strip_tags($item['pg_content_2']);
# get the first 500 letters only
$pg_content = substr($pg_content, 0, 500);
# get the matches
if (preg_match("/\b(".$search.")\b/", $pg_content))
{
$match[] = $pg_content;
}
}
$total_match = count($match);
//echo $count;
}
if($total_match > 0)
{
echo '<result message="'.$total_match.' matches found! Please wait while redirecting." search="'.$search.'"/>';
}
else
{
echo '<error elementid="input" message="Sorry no results are found."/>';
}