-2
我真的有單獨的問題,我需要幫助。我只想顯示來自'內容'的20個字符。只顯示來自內容的20個字符?顯示段落?
<?php
$output = '';
if(isset($_GET['q']) && $_GET['q'] !== ' ') {
$searchq = $_GET['q'];
$q = mysqli_query($db, "SELECT * FROM article WHERE title LIKE '%$searchq%' OR content LIKE '%$searchq%'") or die(mysqli_error());
$c = mysqli_num_rows($q);
if($c == 0) {
$output = 'No search results for <strong>"' . $searchq . '"</strong>';
} else {
while($row = mysqli_fetch_array($q)) {
$id = $row['id'];
$title = $row ['title'];
$content = $row ['content'];
$output .= '<a href="article.php?id=' .$id. '">
<h3>'.$title.'</h3></a>'.$content.'';
}
}
} else {
header("location: ./");
}
print("$output");
mysqli_close($db);
?>
獨立的問題應該分開詢問。 – Shadow
請注意:您的代碼對於SQL注入攻擊是開放的。使用「$ searchq = mysqli_escape_string($ _ GET ['q']);」 – snitch182