hi am new in php, i have values like A,B,C,D in database all in one box.
i made a dropdown for its search A B C D , i want if somebody select A or B and search it fetch the whole row from database.

or in other words i put the values in database by selecting multiple options by using implode, now i don know how to fetch them in search page if somebody select only one value from saved ones like only A or B or C...please help, m not familiar with functions alot so please help with coding if possible, thank you.

Show what you have so far. For the mysql query to work, have a look at the FIND_IN_SET() function.

can you please paste your code here??

can you please paste your code here??

Here is the code how i put values in database:

HTML............
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Register</title>
</head>

<body>
<form enctype="multipart/form-data" action="CandidateRegisterSubmit.php" method="post" >
<table width="100%" border="0">
<tr><td>Preferred Job Location</td>
<td>
<select multiple="multiple" name="PreferredCity[]">
<?php include("easy/CurrentLocation.php");?>
</select></td></tr>

<tr><td>Preferred Industry</td>
<td>
<select multiple="multiple" name="PreferredIndustry[]">
<?php include("easy/CurrentIndustry.php");?>
</select></td></tr>


<td colspan="2" align="center"><input type="submit" name="ConfirmPass"/></td>
</tr>
</table>
</form>
</body>
</html>


Submit..............

<?php session_start();
include("includes/connection.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php

$PreferredCity= $_REQUEST;
$PrefCity = implode(',' , $PreferredCity);
$PreferredIndustry= $_REQUEST;
$PrefIndustry = implode(',' , $PreferredIndustry);


$sql= "INSERT INTO candidates ( PrefCity ,PrefIndustry ) VALUES ( '$PrefCity', '$PrefIndustry')";
mysql_query($sql);
$_SESSION=$UserName;?>

</body>
</html>

NOw i Want to Search it by.......


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Magic Search</title>
</head>

<body>
<form action="MagicSearchSubmit.php" method="get">
<table width="100" border="0" align="center">
<caption><b><big>Magic Search</caption>
<tr>
<td>Industry</td>
<td><SELECT id="PrefIndustry" style="width: 370px;" name="PrefIndustry" class="">
<?php include("easy/CurrentIndustry.php"); ?></SELECT></td>
</tr>
<tr>
<td>Location</td>
<td><SELECT name="PrefCity" id="PrefCity" style="width:190px" class="" onkeydown="return trapKey(event,this)">
<?php include("easy/CurrentLocation.php"); ?></SELECT></td>
</tr>

<tr>
<td colspan="2" align="center"><input type="submit" value="Search"/></td>
</tr>
</table>
</form>


</body>
</html>


Hope it explains all...

try this on query on MagicSearchSubmit.php

if(isset($_GET['PrefIndustry']))
{
  $q = $_GET['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
elseif(isset($_POST['PrefIndustry']))
{
  $q = $_POST['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
else
{
  $q = NULL;
}

$query = "select * from candidates where PrefCity like '".$q."%'";
$result = mysql_query($query) or die('Error in Search Query!<br />'.mysql_error());

// If want to fetch single result
$row = mysql_fetch_array($result);

echo $row['field1'].$row['field2'];

// or you want to fetch whole similar result use while()

hope it will help you,,

let me know

try this on query on MagicSearchSubmit.php

if(isset($_GET['PrefIndustry']))
{
  $q = $_GET['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
elseif(isset($_POST['PrefIndustry']))
{
  $q = $_POST['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
else
{
  $q = NULL;
}

$query = "select * from candidates where PrefCity like '".$q."%'";
$result = mysql_query($query) or die('Error in Search Query!<br />'.mysql_error());

// If want to fetch single result
$row = mysql_fetch_array($result);

echo $row['field1'].$row['field2'];

// or you want to fetch whole similar result use while()

hope it will help you,,

let me know

<?php include("includes/connection.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Magic Search Submit</title>
</head>

<body>
<a href="logout.php">LOGOUT</a>  
  <table width="100%" border="1">
  
   <tr><td align="center">id</a></td> 
  <td align="center">PrefCity</td>
 
 </tr>
<?php
$PrefCity =$_REQUEST['PrefCity'];

$PrefIndustry =$_REQUEST['PrefIndustry'];

$Experience =$_REQUEST['Experience'];

$sql= "SELECT * FROM candidates WHERE ";
if(isset($_GET['PrefIndustry']))
{
  $q = $_GET['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
elseif(isset($_POST['PrefIndustry']))
{
  $q = $_POST['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
else
{
  $q = NULL;
}
 
$query = "select * from candidates where PrefCity like '".$q."%'";
$result = mysql_query($query) or die('Error in Search Query!<br />'.mysql_error());
 
 
// or you want to fetch whole similar result use while()
while($row = mysql_fetch_array($result))
{
$id= $row['id'];
$PrefCity= $row['PrefCity'];
//$Experience= $row['Experience'];
echo  "<tr>
    <td>$id</td>
    <td>$PrefCity</td>
   </tr>";}
?>
</body>
</html>

Thank you for your reply,still not showing any result see if am doing anything wrong.

<?php include("includes/connection.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Magic Search Submit</title>
</head>

<body>
<a href="logout.php">LOGOUT</a>  
  <table width="100%" border="1">
  
   <tr><td align="center">id</a></td> 
  <td align="center">PrefCity</td>
 
 </tr>
<?php
$PrefCity =$_REQUEST['PrefCity'];

$PrefIndustry =$_REQUEST['PrefIndustry'];

$Experience =$_REQUEST['Experience'];

$sql= "SELECT * FROM candidates WHERE ";
if(isset($_GET['PrefIndustry']))
{
  $q = $_GET['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
elseif(isset($_POST['PrefIndustry']))
{
  $q = $_POST['PrefIndustry'];
  $q = mysql_real_escape_string($q);
}
else
{
  $q = NULL;
}
 
$query = "select * from candidates where PrefCity like '".$q."%'";
$result = mysql_query($query) or die('Error in Search Query!<br />'.mysql_error());
 
 
// or you want to fetch whole similar result use while()
while($row = mysql_fetch_array($result))
{
$id= $row['id'];
$PrefCity= $row['PrefCity'];
//$Experience= $row['Experience'];
echo  "<tr>
    <td>$id</td>
    <td>$PrefCity</td>
   </tr>";}
?>
</body>
</html>

In search term, it is necessary to get what we have to search and is that search is in our database?, and in which field of our database?

first we have to conform about the $_REQUEST value?
if is correct then we get the result.

<?php include("includes/connection.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Magic Search Submit</title>
</head>

<body>
<a href="logout.php">LOGOUT</a>  
  <table width="100%" border="1">
  
   <tr><td align="center">id</a></td> 
  <td align="center">PrefCity</td>
 
 </tr>
<?php

$PrefCity =$_REQUEST['PrefCity'];

// conform about the value
echo $PrefCity;

// $PrefIndustry =$_REQUEST['PrefIndustry'];

// $Experience =$_REQUEST['Experience'];

// Don't have to write this query.
// $sql= "SELECT * FROM candidates WHERE ";

if(isset($PrefCity))
{
  $q = $PrefCity;
  $q = mysql_real_escape_string($q);
}
else
{
  $q = NULL;
}
 
 # Please check the filed name is correct or not near where
 
$query = "select * from candidates where PrefCity like '".$q."%'";
$result = mysql_query($query) or die('Error in Search Query!<br />'.mysql_error());
 
 
// or you want to fetch whole similar result use while()
while($row = mysql_fetch_array($result))
{
$id= $row['id'];
$PrefCity= $row['PrefCity'];
//$Experience= $row['Experience'];
echo  "<tr>
    <td>$id</td>
    <td>$PrefCity</td>
   </tr>";}
?>
</body>
</html>

hope it will help you to understant

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.