By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,354 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,354 IT Pros & Developers. It's quick & easy.

Why my search engine function are limited

P: 34
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">Alat Balai</option>
<Option VALUE="Komunikasi">Alat Komunikasi</option>
<Option VALUE="NamaPeralatan">Inventory</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>Results</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($find);
$find = strip_tags($find);
$find = trim ($find);

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


echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>NamaPeralatan</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_array( $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=mysql_num_rows($data);
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>Searched For:</b> " .$find;
}
?>
Sep 23 '06 #1
Share this Question
Share on Google+
1 Reply


P: 16
now im pretty new here, but i dont think you should keep posting this question in different ways, it just hogs the forum
Sep 23 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.