PHP Classes

File: search.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   Searchy PHP Search Engine   search.php   Download  
File: search.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Searchy PHP Search Engine
Crawl, index and search multiple Web sites
Author: By
Last change:
Date: 1 year ago
Size: 3,587 bytes


Class file image Download

include_once 'config.php';

if (!isset(
$_GET['k'])) {
header('Location: index.php');

$keyword = $_GET['k'];

$page = (!isset($_GET['page'])) ? 1 : $_GET['page'];

$db = new Database($config);
$se = new SearchEngine($db);

$sites = $se->findSites($keyword, $page);


<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Searchy - <?php echo $keyword; ?></title>
    <link href="" rel="stylesheet">

    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">Searchy</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>

            <div class="collapse navbar-collapse" id="navbarColor02">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="index.php">Home</a>
                    <li class="nav-item">
                        <a class="nav-link" href="add.php">Add Site</a>
                    <li class="nav-item">
                        <a class="nav-link" href="crawl.php">Crawl Site</a>

    <div class="container">
        <div class="pt-3">
            <form class="d-flex" method="GET" action="search.php">
                <input class="form-control me-sm-2" type="text" name="k" value="<?= $_GET['k']; ?>" placeholder="Search">
                <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>

        <div class="pt-4">
            <div class="d-flex justify-content-between">
                <p>You searched for <b>"<?php echo $keyword ?>"</b></p>

                <p><b><?php echo $sites['count']; ?></b> results found</p>

        <hr />

        <div class="pt-3">
                <?php foreach ($sites['results'] as $site) : ?>

                        <a href="<?php echo $site->url ?>">
                            <h3><?php echo $site->title ?></h3>
                        <p><?php echo $site->blurb ?></p>

                <?php endforeach; ?>

        <div class="pt-5">
            <ul class="pagination pagination-sm">
                <?php for ($page = 1; $page <= $sites['pages']; $page++) : ?>
<li class="page-item <?php echo isset($_GET['page']) && $_GET['page'] == $page ? 'active' : '' ?>">
                        <a class="page-link" href="search.php?k=<?= $keyword ?>&page=<?= $page ?>"><?= $page; ?></a>
                <?php endfor; ?>

    <script src=""></script>
    <script src=""></script>