Skip to content
Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

Youths Forum Youths Forum Youths Forum

Tech Blogs & Programming Tutorials

  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones

Categories

  • Automobiles (12)
    • Cars (7)
  • Blog (103)
    • Poems (2)
    • Space (2)
  • Command (2)
  • Education (2)
  • Entertainment (4)
  • Gadgets (9)
    • Phones (8)
      • Android Phones (4)
  • HTML Templates (11)
  • IT Training Institutes (1)
  • Lifestyle (4)
  • News (51)
  • Others (23)
  • Programming (296)
    • API (16)
    • CSS (83)
    • Database (4)
    • Hosting (1)
    • HTML (37)
    • JavaScript (117)
      • JQuery (27)
      • ReactJS (7)
    • PHP (116)
  • Python (3)
  • recipes (1)
  • SEE Result (1)
  • Server (3)
  • Blog
  • News
  • Programming
    • PHP
    • JavaScript
    • JQuery
    • CSS
    • HTML
    • API
  • Stock Market Live
  • Automobiles
    • Cars
  • Gadgets
    • Phones
    • Android Phones
Close

Search

PHP

Develop a Custom Search Engine Using PHP and MySQL

By Admin
December 17, 2024 3 Min Read
0

Creating a custom search engine is an essential project for web developers interested in enhancing their knowledge of PHP and MySQL. In this article, we will guide you through building a simple yet functional search engine using PHP and MySQL.

Why Build a Custom Search Engine?

Developing a custom search engine allows you to:

  • Understand the fundamentals of search queries.
  • Enhance database management skills.
  • Create customized search experiences tailored to specific applications.

Follow this video for complete guidance :

https://www.youtube.com/watch?v=dDOuxGcjfns

Full Source Code

Create a table named “pages” with necessary columns as defined in following SQL query :

CREATE TABLE pages (
    id INT AUTO_INCREMENT PRIMARY KEY,
    url VARCHAR(255) NOT NULL,
    title VARCHAR(255) NOT NULL,
    description TEXT,
    keywords TEXT
);

Then use following source code :

<?php

// Database connection
$conn = new mysqli("localhost", "root", "", "search_engine");

if (isset($_GET['query'])) {
    $query = $conn->real_escape_string($_GET['query']);
    $sql = "SELECT * FROM pages WHERE url LIKE '%$query%' or title LIKE '%$query%' OR description LIKE '%$query%' OR keywords LIKE '%$query%'";
    $result = $conn->query($sql);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Custom Search Engine</title>
    <style>

		@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900');


        body {
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
            text-align: center;
            padding-top: 100px;
        }
        .search-box {
            max-width: 800px;
            margin: 0 auto;
        }
        .logo {
            font-size: 64px;
            font-weight: bold;
            color: #4285f4;
            font-family: "Barlow Condensed", serif;;
        }
        .logo span {
            margin-left:10px;
            color: #ea4335;
        }
        .search-form {
            margin-top: 20px;
        }
        input[type="text"] {
            width: 60%;
            padding: 15px;
            font-size: 18px;
            border: 1px solid #dfe1e5;
            border-radius: 24px;
            outline: none;
            box-shadow: 0 1px 6px rgba(32, 33, 36, 0.28);
        }
        input[type="submit"] {
            padding: 10px 20px;
            font-size: 16px;
            color: white;
            background: #4285f4;
            border: none;
            border-radius: 24px;
            cursor: pointer;
            margin-left: 10px;
        }
        input[type="submit"]:hover {
            background: #357ae8;
        }
        .results {
            margin-top: 40px;
            text-align: left;
            max-width: 800px;
            margin: 0 auto;
        }
        .result-item {
            background: white;
            padding: 20px;
            margin: 10px 0;
            border-radius: 8px;
            box-shadow: 0 1px 6px rgba(32, 33, 36, 0.28);
        }
        .result-item a {
            color: #1a0dab;
            font-size: 20px;
            font-weight: bold;
            text-decoration: none;
        }
        .result-item .url {
            color: #006621;
            font-size: 14px;
            margin: 4px 0;
        }
        .result-item p {
            color: #4d5156;
            margin: 8px 0 0;
        }
    </style>
</head>
<body>
<div class="search-box">
    <div class="logo">Custom<span>Search</span></div>
    <form class="search-form" method="GET" action="">
        <input type="text" name="query" placeholder="Search here..." required>
        <input type="submit" value="Search">
    </form>
</div>

<?php if (isset($result)){ ?>
<div class="results">
    <?php if ($result->num_rows > 0){ ?>
        <?php while ($row = $result->fetch_assoc()){ ?>
            <div class="result-item">
                <a href="<?php echo htmlspecialchars($row['url']);?>" target="_blank">
                    <?php echo htmlspecialchars($row['title']);?>
                </a>
                <div class="url"><?php echo htmlspecialchars($row['url']);?></div>
                <p><?php echo htmlspecialchars($row['description']);?></p>
            </div>
        <?php } ?>
    <?php } else{ ?>
        <p>No results found.</p>
    <?php } ?>
</div>
<?php } ?>
</body>
</html>

Project Overview

Our search engine will query a MySQL database for relevant results based on user input. The search results will display the page title, URL, and description, styled to resemble a professional search interface.

Requirements

Before starting, ensure you have the following:

  • A web server with PHP support (e.g., XAMPP or WAMP).
  • MySQL database setup.
  • Basic understanding of PHP, HTML, and CSS.

Setting Up the Database

  • Create a Database: Name it search_engine.
  • Create a Table: Name it pages, with columns id, title, url, description, and keywords.
  • Insert Sample Data: Populate the table with sample pages.

Project Breakdown

  • Database Connection: Connect PHP to MySQL using mysqli.
  • Search Query Execution: Use a query that matches user input against multiple fields (title, description, keywords).
  • Display Results: If matches are found, display them in a styled format with clickable links.
  • User Interface Design: Ensure a clean, user-friendly layout inspired by popular search engines.

Features to Enhance

To further develop this project, consider adding:

  • Pagination for search results.
  • Advanced search filters.
  • Improved relevance ranking using full-text search.
  • Secure input handling to prevent SQL injection.

Building a custom search engine using PHP and MySQL is a practical project for aspiring web developers. It enhances coding skills while offering a valuable, real-world application. Start small, experiment with features, and continuously refine your search engine to improve its performance and user experience.

Tags:

custom search enginePHPsearch engine
Author

Admin

Follow Me
Other Articles
Previous

Part 3 : Enhancing the File Manager with a File Upload Feature

Next

CSV Read and Write Using jQuery

No Comment! Be the first one.

Leave a Reply

Your email address will not be published. Required fields are marked *

FIFA World Cup 2026 Predict and Win by SportsGuff

Recent Posts

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide
  • Chiranjibi Adhikari Appointed Acting President of CAN Federation
  • How to Design a Student Marksheet Using HTML and CSS

Tags

adsense ai animate animation animation using HTML and CSS API blog calculator chatgpt Cryptocurrency CSS css animation design Email Facebook featured filemanager file manager free template google htaccess HTML image Instagram interview javascript JQuery jquery ui NADA AutoShow NADA Auto Show 2024 password PHP Progressive Web App PWA QR random react reactjs Rotate travel Twitter vpn youthforum youthsforum youtube

About Us

At Youths Forum, we are passionate about sharing knowledge that empowers students, educators, professionals, and technology enthusiasts.

Our Mission

Our mission is simple: to make technology and education accessible, understandable, and beneficial for everyone. We strive to create content that helps our readers learn new skills and stay updated with industry developments.

RSS RSS

  • Unpacking Nepal’s Record Rs 2.12 Trillion Budget and What It Means for You Admin
  • How to Write a Strong Scholarship Application: The Ultimate Step-by-Step Guide Admin
  • How to Prepare for Exams Without Stress: The Ultimate Science-Backed Guide Admin

Quick Links

  • Stock Market Live
  • Parliament Election 2082
Copyright 2026 — Youths Forum. All rights reserved. Blogsy WordPress Theme