Updated question
Below works if I type 'format bibliotek' or 'format' or 'bibliotek' 1 post contains 'bibliotek' and 1 post contains 'format' in column knowmed_content. But if I search for 'bib', nothing is returned?
if(isset($_POST['SearchIt'])) {
$SearchIt = $_POST['SearchIt'];
} else {
$SearchIt = Null;
}
if(isset($SearchIt)) {
$getknowledge = $conn->prepare("SELECT * FROM knowmed_main WHERE MATCH (knowmed_content) AGAINST ('%".$SearchIt."%' IN BOOLEAN MODE)");
} else {
$getknowledge = $conn->prepare("SELECT k.knowmed_id, k.knowmed_headline, k.knowmed_content, k.knowmed_tags, k.knowmed_created_by, k.entry_date, k.knowmed_active, u.Fname FROM knowmed_main AS k INNER JOIN users AS u ON k.knowmed_created_by = u.userid ORDER BY k.knowmed_id");
}
$getknowledge->execute();
$resultknowledge = $getknowledge->get_result();
$getknowledge->close();
if ($resultknowledge->num_rows > 0) {
while($row = $resultknowledge->fetch_assoc()) {
$getknowmedId = $row["knowmed_id"];
$getknowmedHeadline = $row["knowmed_headline"];
$getknowmedContent = $row["knowmed_content"];
$getknowmedUserentry = $row["knowmed_created_by"];
echo "<li><a class=\"read-more\" href=\"read-question.php?dpid=".$getknowmedId."\" title=\"Læs mere\"><div class=\"bottom\">Spørgsmål oprettet d. <br />Af: ".$getknowmedUserentry."</div><div class=\"contentText\"><p><b>".$getknowmedHeadline."</b></p></div></li></a>";
}
} else {echo "Either no questions are created or search result returns empty..";}?>
CodePudding user response:
you can use mysql regexp. it search based on given pattern.
try this code and change respect table_name, column_name
select * from table_name where column_name regexp 'first_word|second_word'
CodePudding user response:
Found it.
$getknowledge = $conn->prepare("SELECT * FROM knowmed_main WHERE MATCH (knowmed_content) AGAINST ('*".$SearchIt."*' IN BOOLEAN MODE)");