Jump to content

Website Search Script


Tero20051

Recommended Posts

Hey everyone, thanks god i found this forum ... i have a little problem with my up-comming project and if you have a bit of time, to help me and give me some suggestions of what scripts and stuff should i use.

 

Well if you wander, i want to make a website like this one http://www.pwdatabase.com/ where to make a menu and add some categories, like

 

[ Items ] - [ NPC ] - [ Monsters ] - [ Quests ] these categories will also represent a folder on the website, for example website.com/items - website.com/npc and somewhere bellow i wold like to add this search option where when you tipe a word, al quests, npc items or mobs that contain this word to be displayed there.

 

I hope you got it what i wold like to make, please take your time and try to suggest me some scripts, or anything.

 

Thanks you a lot,

 

~Tero20051

 

Link to comment
Share on other sites

This is easily done if all your items, NPCs, etc. are stored in their own databases. 

Just make a search.php page, add database query to check databases for keywords given and output to page.

Add a search box to pages you want it to be seen or used.

 

example search.php:

<?php

$host = "HOST";
$user = "USER";
$pass = "PASS";
$db = "Database";

// Connect to database, call error if no connection.
$con = new MySQLi($host, $user, $pass, $db);
if (!$con) {
    echo "Failed to connect to database!" . mysqli_error();
}

if (isset($_POST['search'])) {
    $key = addslashes($_POST['search']);  //in case any items, npc's etc would have ' in the name.
    $sql = "SELECT id, item_name, item_stats FROM items WHERE item_name LIKE CONCAT('%', ?, '%')";
    $query = $con->prepare($sql);
    $query->bind_param('s', $key);
    $query->bind_result($id, $iname, $istats);
    $query->execute();
    $query->store_result();
    while ($query->fetch()) {
        echo $id . ", " . $iname . ", " . $istats . "<br />";// nice neat html tables, divs, w/e your flavor - to display information.
    }
    $query->free_result();
    $query->close();
}

This is just a quick and dirty example of the search.php. There would be a lot more (such as error handling, more complex queries to request data from several tables, etc. to go along with it), but was just showing how simple it is to get the data you seek.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.