我有一个单独的问题,我需要帮助。我只想显示来自'内容'。
的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);
?>
答案 0 :(得分:0)
我将回答你的第一个问题:
在此之后插入此行:
$content = $row ['content'];
if(strlen($content)>20) $content=substr ($content,0,19);