Search Engine

php Malaysia
  • 17 years ago

    Hi, im very new in PHP. What i want to asked is where i can find a script to do a simple search engine by using php connect to the mySQL. for example i have list of music in my database, and i want to search by Song title, Artis, or price. Thanks
    H!

  • 17 years ago

    Hi RedSouljaz,


    You could build your own small search engine for this, like so


    Search.html


    Code:


    <form action="result.php" method="get">
    <input type="text" name="search"><br>
    <input type="radio" name="option" value="1" checked> All<br>
    <input type="radio" name="option" value="2"> Song<br>
    <input type="radio" name="option" value="3"> Artist<br>
    <input type="radio" name="option" value="4"> Price<br>
    <input type="submit" value="search">
    </form>




    result.php

    Code:


    //database connection code here


    switch $GET["option"] {
     case 1:
       sql = "select * from mytable where song like '%".$
    GET["search"]."%' and artist like '%".$GET["search"]."%' and price like '%".$GET["search"]."%' ";
       break;
     case 2:
       sql = "select * from mytable where song like '%".$GET["search"]."%' ";
       break;
     case 3:
       sql = "select * from mytable where artist like '%".$
    GET["search"]."%' ";
       break;
     case 4:
       sql = "select * from mytable where price like '%".$GET["search"]."%' ";
       break;
     default:
       sql = "select * from mytable where song like '%".$
    GET["search"]."%' and artist like '%".$GET["search"]."%' and price like '%".$GET["search"]."%' ";
       break;
    }


    // code to run query and show results on page....




    hope this helps


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski