글 삭제

작성자 본인만 삭제할 수 있습니다

← 홈으로
2023.07.15 · 조회 10,366
html 파일에서 input으로 받은 검색어(txt)를 php에서 full text search로 검색
<p>html 예제:</p><p></p><p></p><p></p><p>&lt;!DOCTYPE html&gt;</p><p>&lt;html&gt;</p><p>&lt;head&gt;</p><p>&nbsp; &nbsp; &lt;title&gt;Full-Text Search 예제&lt;/title&gt;</p><p>&lt;/head&gt;</p><p>&lt;body&gt;</p><p><br></p><p>&lt;h2&gt;Full-Text Search&lt;/h2&gt;</p><p>&lt;form action="search.php" method="post"&gt;</p><p>&nbsp; &nbsp; 검색어: &lt;input type="text" name="searchQuery" required&gt;</p><p>&nbsp; &nbsp; &lt;input type="submit" value="검색"&gt;</p><p>&lt;/form&gt;</p><p><br></p><p>&lt;/body&gt;</p><p>&lt;/html&gt;</p><div>php 파일 예제:</div><div><br></div><div><div><div>// MariaDB 접속 정보</div><div>$servername = "localhost";</div><div>$username = "your_username";</div><div>$password = "your_password";</div><div>$dbname = "your_database";</div><div><br></div><div>// 사용자로부터 검색어 입력 받기</div><div>if (isset($_POST['searchQuery'])) {</div><div>&nbsp; &nbsp; $searchQuery = $_POST['searchQuery'];</div><div><br></div><div>&nbsp; &nbsp; // 데이터베이스 연결</div><div>&nbsp; &nbsp; $conn = new mysqli($servername, $username, $password, $dbname);</div><div><br></div><div>&nbsp; &nbsp; // 연결 확인</div><div>&nbsp; &nbsp; if ($conn-&gt;connect_error) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; die("Connection failed: " . $conn-&gt;connect_error);</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; // 검색어에 대해 Full-Text Search 쿼리 작성 및 실행</div><div>&nbsp; &nbsp; $sql = "SELECT * FROM articles WHERE MATCH(title, content) AGAINST ('$searchQuery' IN BOOLEAN MODE)";</div><div>&nbsp; &nbsp; $result = $conn-&gt;query($sql);</div><div><br></div><div>&nbsp; &nbsp; if ($result-&gt;num_rows &gt; 0) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; // 검색 결과 출력</div><div>&nbsp; &nbsp; &nbsp; &nbsp; while ($row = $result-&gt;fetch_assoc()) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "ID: " . $row["id"] . ", Title: " . $row["title"] . ", Content: " . $row["content"] . "<br>";</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; } else {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; echo "검색 결과가 없습니다.";</div><div>&nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; // 연결 종료</div><div>&nbsp; &nbsp; $conn-&gt;close();</div><div>}</div><div>?&gt;</div></div></div>
삭제된 게시글은 복구할 수 없습니다