Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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);
- <?php
- if(!empty($_GET['id']))
- {
- $sql = "
- SELECT id, title, content
- FROM article
- ";
- // then do the query, etc....
- }
- $results = $db->query($sql);
- if($results->num_rows) {
- While($row = $results->fetch_object()) {
- $title = htmlentities($row->title);
- $content = nl2br(htmlentities($row->content));
- echo "
- <h2>{$row->title}</h2>
- {$row->content}
- ";
- }
- } else {
- echo 'No Results';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement