Search in php, little mistake
I am writing a php web site. I have to finish it until tomorrow.

Everything is working, one problem: there is a mistake in search.

If finds according to one option-according to surname.

But in other cases like name, patronymic  it does not find.

What is the problem could you help me please?

And I am begging you not to put minuses for my topic.


    

**`table.php`**

  
    
    <form name="searching" action="search.php" method="post"> 
    Gözleg : <input type="text" name="search" /> 
    
    <select name="choice">
    <option> Ählisine görä </option>
    <option value="surname"> Familiýasyna görä </option>
    <option value="name"> Adyna görä </option>
    <option value="patronymic"> Atasynyň adyna görä </option>
    </select>
    
    <input type="submit" value="Tap" name="tap"/>
    </form>

    

**search.php**


    
    <?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=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php
    
     $choice=$_POST["choice"];
     $search=$_POST["search"];

    switch ($choice) {
    case "surname":
        $query = "SELECT * FROM maglumat where surname like '%$search%' ORDER BY id, adress";
        break;
    case "name":
        $query = "SELECT * FROM maglumat where name like '%$search%' ORDER BY id, adress";
        break;
    }
    
    	        
    	        $result = mysql_query($query);
    			$num_results = mysql_num_rows($result);
    			
    			
    				echo "<br />";
    			echo "<table border=1 bordercolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" style=\"text-align:center; font-size:9pt;\" >";
    echo "<tr bgcolor=\"#99FFFF\" style=\"font-family:'Times New Roman', Times, serif; font-weight:bold; font-size: 9pt;\">";
    echo "	<td>№</td>
    		<td>Familiýasy</td>
    		<td>Ady</td>
    		<td>Atasynyň ady</td>
    		
    echo "</tr>";
    for ($i=0; $i < $num_results; $i++)
    {
    	$row = mysql_fetch_array($result);
    	$counter = $i+1;
    	if($i%2==1){
    	  echo "<tr bgcolor=\"#CCCCCC\">";
    	}
    	else
    	echo "<tr>";
    	echo "	<td>$counter</td>
    			<td>".$row["surname"]."</td>
    			<td>".$row["name"]."</td>
    			<td>".$row["patronymic"]."</td>
    			  			
    			
    	echo "</tr>";
    }
    echo "</table>";
    	 			  
    	  
    ?>
  
    
    </body>
    </html>
Search in php, little mistake
===

I am writing a php web site. I have to finish it until tomorrow.

Everything is working, one problem: there is a mistake in search.

If finds according to one option-according to surname.

But in other cases like name, patronymic  it does not find.

What is the problem could you help me please?

And I am begging you not to put minuses for my topic.


    

**`table.php`**

  
    
    <form name="searching" action="search.php" method="post"> 
    Gözleg : <input type="text" name="search" /> 
    
    <select name="choice">
    <option> Ählisine görä </option>
    <option value="surname"> Familiýasyna görä </option>
    <option value="name"> Adyna görä </option>
    <option value="patronymic"> Atasynyň adyna görä </option>
    </select>
    
    <input type="submit" value="Tap" name="tap"/>
    </form>

    

**search.php**


    
    <?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=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php
    
     $choice=$_POST["choice"];
     $search=$_POST["search"];

    switch ($choice) {
    case "surname":
        $query = "SELECT * FROM maglumat where surname like '%$search%' ORDER BY id, adress";
        break;
    case "name":
        $query = "SELECT * FROM maglumat where name like '%$search%' ORDER BY id, adress";
        break;
    }
    
    	        
    	        $result = mysql_query($query);
    			$num_results = mysql_num_rows($result);
    			
    			
    				echo "<br />";
    			echo "<table border=1 bordercolor=\"#000000\" cellspacing=\"1\" cellpadding=\"3\" style=\"text-align:center; font-size:9pt;\" >";
    echo "<tr bgcolor=\"#99FFFF\" style=\"font-family:'Times New Roman', Times, serif; font-weight:bold; font-size: 9pt;\">";
    echo "	<td>№</td>
    		<td>Familiýasy</td>
    		<td>Ady</td>
    		<td>Atasynyň ady</td>
    		
    echo "</tr>";
    for ($i=0; $i < $num_results; $i++)
    {
    	$row = mysql_fetch_array($result);
    	$counter = $i+1;
    	if($i%2==1){
    	  echo "<tr bgcolor=\"#CCCCCC\">";
    	}
    	else
    	echo "<tr>";
    	echo "	<td>$counter</td>
    			<td>".$row["surname"]."</td>
    			<td>".$row["name"]."</td>
    			<td>".$row["patronymic"]."</td>
    			  			
    			
    	echo "</tr>";
    }
    echo "</table>";
    	 			  
    	  
    ?>
  
    
    </body>
    </html>