搜索更多列

时间:2013-01-30 15:21:33

标签: php sql search

这是一个可以在数据库中搜索的程序。 但我想搜索Postcode和Huisnummer列。但我尝试的一切都行不通。任何人的想法

<!DOCTYPE html>
<html lang="nl">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="index1.css" />
        <title>Inboedelwaarde op adres</title>
    </head>
    <body>
    <p>
        <form action="zoekadres.php" method="post"> 
        Postcode: <input type="text" name="term" /><br />       
        <input type="submit" name="submit" value="Zoek" />   
        </form>
    </p>
    </body>
</html>


<html lang="nl">
    <head>
        <meta charset="utf-8">
        <title>Inboedelwaarde</title>
    </head>
    <body>  
        <?php      
        mysql_connect ("localhost", "root","")  or die (mysql_error());
        mysql_select_db ("inboedelmeter");
        $term = $_POST['term'];
        $sql = mysql_query("SELECT Postcode, Huisnummer, Toevoeging, Inboedelwaarde 
                            FROM puntentotaal 
                            WHERE Postcode like '%$term%'");
            while ($row = mysql_fetch_array($sql)){  
            echo 'Postcode: '.$row['Postcode'];    
            echo '<br/> Huisnummer: '.$row['Huisnummer'];    
            echo '<br/> Toevoeging: '.$row['Toevoeging'];    
            echo '<br/> Uw inboedelwaarde is EURO € '.$row['Inboedelwaarde'];
            echo '<br/><br/>';
            }
                echo "<p><form action='adresbekijken.php' method='post'>
                        <input type='submit' name='submit' value='Opnieuw zoeken'>"
        ?>
    </body>
</html>

谢谢!

2 个答案:

答案 0 :(得分:0)

试试这个WHERE Postcode like '%' . $term . '%'");

答案 1 :(得分:0)

代码

$sql = mysql_query("SELECT Postcode, Huisnummer, Toevoeging, Inboedelwaarde FROM puntentotaal WHERE Postcode like '%$term%'");

您正在搜索所有字段。尝试将其更改为“SELECT Postcode,Huisnummer WHERE Postcode like'%$ term%'”;“。

所以你只想搜索那些柱子。