Why my search engine function are limited

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sheau Wei
    New Member
    • Sep 2006
    • 34

    Why my search engine function are limited

    Below is my search engine code.
    I realize that the function was very limitied because i cannot searching the "NamaPealatan"( name of tools) compatible to the either categories Operasi or Balai or Komunikasi .

    If i want to add radio option in this code to minimize the area of searching, leet say at column Motor,(the option will be bermotor or Notmotor) how do i do?

    Below is my database

    CREATE TABLE `listofitem` `ID` INT( 10 ) NOT NULL AUTO_INCREMENT ,
    `NamaPeralatan` VARCHAR( 30 ) NOT NULL ,
    `Motor` VARCHAR( 10 ) NULL DEFAULT NULL ,
    `Operasi` VARCHAR( 30 ) NULL DEFAULT NULL ,
    `Balai` VARCHAR( 30 ) NULL DEFAULT NULL ,
    `Komunikasi` VARCHAR( 30 ) NULL DEFAULT NULL

    <?php session_start() ;?>
    <h2>Search</h2>
    <form name="search" method="post" action="<?=$PHP _SELF?>">
    Search for:
    <input type="text" name="find" /> in
    <Select NAME="field">
    <Option VALUE="Operasi" >Alat Operasi</option>
    <Option VALUE="Balai">A lat Balai</option>
    <Option VALUE="Komunika si">Alat Komunikasi</option>
    <Option VALUE="NamaPera latan">Inventor y</option>

    </Select>

    <input type="hidden" name="searching " value="yes" />
    <input type="submit" name="search" value="Search" />
    </form>

    <?
    //This is only displayed if they have submitted the form

    if ($searching =="yes")
    {
    echo "<h2>Result s</h2><p>";

    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>You forgot to enter a search term";
    exit;
    }

    // Otherwise we connect to our Database
    mysql_select_db ("inventory" ) or die(mysql_error ());

    // We preform a bit of filtering
    $find = strtoupper($fin d);
    $find = strip_tags($fin d);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SE LECT * FROM listofitem WHERE upper($field) LIKE'%$find%'") ;


    echo "<table border='1'>";
    echo "<tr> <th>ID</th> <th>NamaPeralat an</th><th>Motor</th><th>Alat Operasi</th><th>Alat Balai</th><th>Alat Komunikasi</th> </tr>";

    //And we display the results
    while($result = mysql_fetch_arr ay( $data ))
    {


    echo "<tr><td>";
    echo $result['ID'];
    echo "</td><td>";
    echo $result['NamaPeralatan'];
    echo "</td><td>";
    echo $result['Motor'];
    echo "</td><td>";
    echo $result['Operasi'];
    echo "</td><td>";
    }
    echo "</table>";



    //This counts the number or results - and if there wasn't any it gives them a little message explaining that
    $anymatches=mys ql_num_rows($da ta);
    if ($anymatches == 0)
    {
    echo "Sorry, but we can not find an entry to match your query<br><br>";
    }

    //And we remind them what they searched for
    echo "<b>Searche d For:</b> " .$find;
    }
    ?>
  • tbb9216
    New Member
    • Sep 2006
    • 16

    #2
    now im pretty new here, but i dont think you should keep posting this question in different ways, it just hogs the forum

    Comment

    Working...