Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:51:28+00:00 2026-06-02T20:51:28+00:00

I’ve built a simple search engine for my site, the way it works is

  • 0

I’ve built a simple search engine for my site, the way it works is when the user enters a keyword it queries the database and displays the results.

My database table looks like this:

game_id title   developer   publisher   genre   release_date    platform          
rating  image_location  description

I want to allow the user to filter through the results once they have made a search, preferably without refreshing the page(only been coding for a month but have a general understanding of jquery and ajax).

Here is my code, im using includes so the search bar, search results and the page that queries are seperated.

page 1 search bar

<div id=\"top_search\">
            <form name=\"input\" action=\"search.php\" method=\"get\" id=\"search_form\">
            <input type=\"text\" id=\"keywords\" name=\"keywords\" size=\"128\" class=\"searchbox\" value=\"$defaultText\"> &nbsp;
            <select id=\category\" name=\"category\" class=\"searchbox\"> 
";
createCategoryList();
echo '
            </select> &nbsp;
            <input type="submit" value="Search" class="button" /> &nbsp;
            </form>
        </div>
        </header>
';

page 2 display results

<?php
session_start();
include ("includes/search_func.php");


if (isset($_GET['keywords'])){
$keywords = mysql_real_escape_string(htmlentities(trim($_GET['keywords']))); 

$errors = array();

if(empty($keywords)){
    $errors[] = 'Please enter a search term';
}else if(strlen($keywords)<3){
    $errors[] = 'Your search term must be at least 3 characters long';
}else if(search_results($keywords) == false){
            $errors[] = 'Your search for'.$keywords.' returned no results';
}
if(empty($errors)){
function diplay_results($keywords){
    $results = search_results($keywords);
    $results_num = count($results);


    foreach($results as $result ){
        echo '
            <div id="game_result">
                <a href= game_page.php?game_id='.$result['game_id'].'><img src= '.$result['image_location'].' id="image" /></a>
                <div id="main_title">
                    <a href= game_page.php?game_id='.$result['game_id'].'><h2 id="game_title">'.$result['title'].'&nbsp; &nbsp;</h2></a>
                    <h3 id="platform">for  &nbsp;'.$result['platform'].'</h3>
                </div>
                <p id=game_description>'.$result['description'].'</p>
                <div id="right_side">
                <h4 id="rating">'.$result['rating'].'</h4>
                </div>
                <hr id="hr"/>
            </div>  
        ';
}
}
}else{
    foreach($errors as $error){
        echo $error, '<br />';
    }
}

}
?>

<!DOCTYPE html>

<html lang="en">
<head>
    <title>Search</title>
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/search.css">
</head>
<body>

    <div id="wrapper">
        <div id="main_aside">
                 //filter navigation will go here
        </div>
        <div id="main_section" class="header">
            <?php diplay_results($keywords)?>
        </div>
    </div>

</body>
</html>

page 3 querying database

<?php 
include 'includes/connect.php';


function search_results($keywords){
$returned_results = array();
$where = "";

$keywords = preg_split('/[\s]+/', $keywords);
$total_keywords = count($keywords);

foreach($keywords as $key=>$keyword){
    $where .= "title LIKE '%$keyword%'";
    if($key != ($total_keywords - 1)){
        $where .= " AND ";
    }   
}
$results ="SELECT * FROM games WHERE $where ";
echo $results;
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;

if($results_num === 0){
    return false;
}else{
    while($row = mysql_fetch_assoc($results)){
        $returned_results[] = array(
            'game_id' => $row['game_id'],
            'title' => $row['title'],
            'platform' => $row['platform'],
            'rating' => $row['rating'],
            'image_location' => $row['image_location'],
            'description' => $row['description'],
        );
    }
    return $returned_results;
}   
}

?>

So in case its not clear i want to allow the user to search for a key term, then it will display from the database any games with the keyword in the title(i already have this part working). Now what cant figure it out is how to let the user filter their results to lets say only action games, along with lets say a certain platform and so on.

Like i said ive only been doing this for a month so if im doing something wrong dont hesitate to call me an idiot, but please help. Any help would be appreciated even links to tutorials or book recommendations.Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:51:31+00:00Added an answer on June 2, 2026 at 8:51 pm

    Your approach is proper. To filter the search results on the basis of publisher name or developer, genre, release date,

    1) You can have another “Advanced Search” Page wherein you could plugin the HTML for these attributes, and just tweak the WHERE clause of your query. So there will be two pages for search – a simple search that will allow the user to filter on the basis of just the title name and say the category and an advanced search page to filter on the basis of the other attributes.
    2) You may even choose to provide options on the basic search page itself for filtering on the basis of additional parameters.

    How you choose your interface would be a decision mandated by your requirement specification. Note that only your WHERE clause will change in all cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a reasonable size flat file database of text documents mostly saved in
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.