Click here to Skip to main content
15,886,805 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a search query to make a search by name and city


it do not seems to work fine i can make search only by inputing name and not by city..

And operator is not working.

here is the whole code..

PHP
if(isset($_POST['vname']))
{
$name=$_POST['vname'];
$missfrom=$_POST['selectmisscity'];
	$sql = "select * from missinginfo where (mfname like '%$name%' or mlname like '%$name%') and city like '%$missfrom%'";
	
	$rs=mysql_query($sql) or die($sql.">>".mysql_error());
	//if(!$rs) die(mysql_error());?>
    
	<table>
    
	<?php 
			$num=mysql_num_rows($rs);
					if($num>0){
	
			while($row = mysql_fetch_assoc($rs)) {
		?>
		<td>
	  	<table>
            <tr>
              <td colspan="2">
			  <div class="record round"><a href="missimgpersondetail.php?key=<?php echo $row['missingid']?>"><img src="<?php echo "http://localhost/projecttest/".$row['photoid'];?> " alt="no image" width="200" height="250" border="1" /></a></div></td>
            </tr>
            <tr>
              <td width="150"><h2 align="center"><?php echo $row['mfname'];?> <?php echo $row['mlname']."<br>";?></h2></td>
              
            </tr>
            
          </table></td>
Posted
Updated 25-Mar-14 18:10pm
v2
Comments
Mohibur Rashid 26-Mar-14 0:58am    
start with echoing the query. then execute the query from command prompt. you will know what to do

1 solution

For your code user has to give name and as well as city to search.

If you want to search only by name then try below query code
PHP
$sql = "select * from missinginfo where mfname like '%$name%' or mlname like '%$name%' ";

Or you want to search by only city then try below code
PHP
$sql="select * from missinginfo where city like '%$missfrom%' ";


If you want to search by anyone of name or city you can try below code
$sql = "select * from missinginfo where mfname like '%$name%' or mlname like '%$name%' or city like '%missform%'";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900