i have this problem of mine, where i don't know the script if we want to retrieve the value of option value in turn to search data. i only the script to retrieve value from input type(text).
please help me on this.

i only know this. this script is to search value by retrieving data from input type text

<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$Location  = $_REQUEST['txtSearch'];


$requestins = $Location . "%" ;


if($Location != "")
{
    $sql = "SELECT * FROM requestins WHERE Location LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
    echo "<p><b></b></p>";

}
else
{
    echo "<table border=1>";


    while($column2=mysql_fetch_array($result))
    {
        extract($column2);

        echo"<tr>";
        echo"<td>Name</td>";
        echo"<td>".$Name."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>IC Number</td>";
        echo"<td>".$ICNo."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Location</td>";
        echo"<td>".$Location ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Exact Location</td>";
        echo"<td>".$ELocation ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Software Name</td>";
        echo"<td>".$SwName ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Remark</td>";
        echo"<td>".$Notes ."</td>";
        echo"</tr>";

    }
    echo"</table>";
}

?>
<?php
if(isset($_POST['submit'])){
      $selectedoption=$_REQUEST['select1'];
      //use $selectedoption in your query. 
}
?>
<html>
<body>
<form method="post" action="test.php">
<select name="select1">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

:) retrieving the option value and using it in a query.

how to implement it in coding above?

Have a select box with all the options! When the user clicks on submit, you REQUEST the value of the select box. $selectedvalue=$_REQUEST['select_box_name'];

im sorry, im so stupid today. can't think very brightly. this code below, shows result from inserting in one text field. so, it still search if i choose option value location, and insert an ic number. supposely it cannot search if i insert that value. i just insert all the code because i dont know where to declare and trace the option value. so, thats why it search all the value insert eventhough the option value is different

<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$Location  = $_REQUEST['txtSearch'];


$requestins = $Location . "%" ;


if($Location != "")
{
    $sql = "SELECT * FROM requestins WHERE Location LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
    echo "<p><b></b></p>";

}
else
{
    echo "<table border=1>";


    while($column2=mysql_fetch_array($result))
    {
        extract($column2);

        echo"<tr>";
        echo"<td>Name</td>";
        echo"<td>".$Name."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>IC Number</td>";
        echo"<td>".$ICNo."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Location</td>";
        echo"<td>".$Location ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Exact Location</td>";
        echo"<td>".$ELocation ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Software Name</td>";
        echo"<td>".$SwName ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Remark</td>";
        echo"<td>".$Notes ."</td>";
        echo"</tr>";

    }
    echo"</table>";
}

?>

<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$SwName= $_REQUEST['txtSearch'];

$requestins = $SwName . "%";


if($SwName != "")
{
    $sql = "SELECT * FROM requestins WHERE SwName LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
    echo "<p><b></b></p>";

}
else
{
    echo "<table border=1>";


    while($column2=mysql_fetch_array($result))
    {
        extract($column2);

        echo"<tr>";
        echo"<td>Name</td>";
        echo"<td>".$Name."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>IC Number</td>";
        echo"<td>".$ICNo."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Location</td>";
        echo"<td>".$Location ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Exact Location</td>";
        echo"<td>".$ELocation ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Software Name</td>";
        echo"<td>".$SwName ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Remark</td>";
        echo"<td>".$Notes ."</td>";
        echo"</tr>";

    }
    echo"</table>";
}

?>


<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$ICNo= $_REQUEST['txtSearch'];

$requestins = $ICNo . "%";


if($ICNo != "")
{
    $sql = "SELECT * FROM requestins WHERE ICNo LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
    echo "<p><b></b></p>";

}
else
{
    echo "<table border=1>";


    while($column2=mysql_fetch_array($result))
    {
        extract($column2);

        echo"<tr>";
        echo"<td>Name</td>";
        echo"<td>".$Name."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>IC Number</td>";
        echo"<td>".$ICNo."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Location</td>";
        echo"<td>".$Location ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Exact Location</td>";
        echo"<td>".$ELocation ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Software Name</td>";
        echo"<td>".$SwName ."</td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td>Remark</td>";
        echo"<td>".$Notes ."</td>";
        echo"</tr>";

    }
    echo"</table>";
}

?>

I dont get it. Where is your dropdown box ? And could you please highlight your code by putting it within [/ code] tags.[code=php ] [/ code] tags.

my dropdown box is in other page. here's the code.this page name searchbylocsoft.php


<form name="form1" method="post" action="viewsearchbylocsoft.php">
<table width="379" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="115" height="41"><label>
<select name="select">
<option value="LOCATION" selected>LOCATION</option>
<option value="SOFTWARE">SOFTWARE</option>
<option value="IC NUMBER">IC NUMBER</option>
</select>
</label></td>
<td width="264"><label>
<input name="txtSearch" type="text" id="txtSearch">

<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$Location = $_REQUEST['txtSearch'];


$requestins = $Location . "%" ;


if($Location != "")
{
$sql = "SELECT * FROM requestins WHERE Location LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
echo "<p><b></b></p>";

}
else
{
echo "<table border=1>";


while($column2=mysql_fetch_array($result))
{
extract($column2);

echo"<tr>";
echo"<td>Name</td>";
echo"<td>".$Name."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>IC Number</td>";
echo"<td>".$ICNo."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Location</td>";
echo"<td>".$Location ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Exact Location</td>";
echo"<td>".$ELocation ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Software Name</td>";
echo"<td>".$SwName ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Remark</td>";
echo"<td>".$Notes ."</td>";
echo"</tr>";

}
echo"</table>";
}

?>
<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$SwName= $_REQUEST['txtSearch'];

$requestins = $SwName . "%";


if($SwName != "")
{
$sql = "SELECT * FROM requestins WHERE SwName LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
echo "<p><b></b></p>";

}
else
{
echo "<table border=1>";


while($column2=mysql_fetch_array($result))
{
extract($column2);

echo"<tr>";
echo"<td>Name</td>";
echo"<td>".$Name."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>IC Number</td>";
echo"<td>".$ICNo."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Location</td>";
echo"<td>".$Location ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Exact Location</td>";
echo"<td>".$ELocation ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Software Name</td>";
echo"<td>".$SwName ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Remark</td>";
echo"<td>".$Notes ."</td>";
echo"</tr>";

}
echo"</table>";
}

?>
<?php

$connect = mysql_connect("localhost","root","") or die ("Could not connect to MYSQL database.");
mysql_select_db("sinventory") or die (my_sql_error());



$ICNo= $_REQUEST['txtSearch'];

$requestins = $ICNo . "%";


if($ICNo != "")
{
$sql = "SELECT * FROM requestins WHERE ICNo LIKE '".$requestins."'";

}
$result = mysql_query($sql) or die ("My SQL Error");
$num_rows = mysql_num_rows($result);




if($num_rows==0)
{
echo "<p><b></b></p>";

}
else
{
echo "<table border=1>";


while($column2=mysql_fetch_array($result))
{
extract($column2);

echo"<tr>";
echo"<td>Name</td>";
echo"<td>".$Name."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>IC Number</td>";
echo"<td>".$ICNo."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Location</td>";
echo"<td>".$Location ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Exact Location</td>";
echo"<td>".$ELocation ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Software Name</td>";
echo"<td>".$SwName ."</td>";
echo"</tr>";
echo"<tr>";
echo"<td>Remark</td>";
echo"<td>".$Notes ."</td>";
echo"</tr>";

}
echo"</table>";
}

?>

the php code above is the only code in page viewsearchbylocsoft.php

When you submit viewsearchbylocsoft.php, do, $select=$_REQUEST; :S where do you want to use it and why do you have the same copy of 3 scripts ?

means that after user select the option value and insert the value in input text, then they will click on search button.then the page will link to viewsearchbylocsoft.php. in this page, (viewsearchbylocsoft.php), it will view the searched data. the scripts looks alike but its different. 1st script for search the location, 2nd script for search the software, and 3rd script for search the IC number, that they had key in. i just combine all the 3 scripts to search all the inserted value (in txtSearch) that related to location,software and IC number. this means that i didn't put the script that will call the value in the drop box.
so, erm where should i put this scipt $select=$_REQUEST;
in my coding above? i know that i should remove the 2 scripts above and left just one script, but i just don't get what script should i put so that there is only one script and it search the value according to drop box value. erm can i have your email? so that i can send you the web interface.

Well, You can do it this way. Have a dropdown box with these options. Have a textbox to take the input from the user. Instead of passing the value as location, software, IC number, etc. you can pass the value as 1,2,3, etc depending upon the choice made by the user. Then when the page is submitted, you can simply check the selected value of the dropdown and do respective search. Eg.

<?php
if(isset($_POST['submit'])){
	$conn=mysql_connect("localhost","root");
	mysql_select_db("test");
	$selectedvalue=$_REQUEST['select'];
	$searchstring=$_REQUEST['search'];
	if($selectedvalue=="1") { // location was selected
		$query="select * from table where location like '%$searchstring%'";
		$result=mysql_query($query);
		// do whatever you want
	}
	if($selectedvalue=="2"){ //IC number was selected
		$query="select * from table where IC_number like '%$searchstring%'";
		$result=mysql_query($query);
		//do whatever you want
	}
	if($selectedvalue=="3"){
	/////////// same like you did for other 2 options
	}
	
}
?>
<html>
<body>
<form method="post" action="test.php">
Select an option: <select name="select">
<option value="1">location </option>
<option value="2">IC number</option>
<option value="3">some other option </option>
</select><br />
<input type="text" name="search"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

So, this way, you can avoid having so many scripts with only a change in 1 line.

Cheers,
Naveen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.