在PHP中创建搜索同时获取两个变量

时间:2017-06-28 09:04:30

标签: php mysql

我正在尝试制作搜索栏,当我这样做时

$sql = "SELECT * FROM info WHERE title LIKE '%".$query."%' OR location LIKE '%".$query."%'OR qualification LIKE '%".$query."%'";

它正确地获取数据,没有问题,然后我尝试做一些事情从数据库中获取2个数据,像这样的东西

$sql = "SELECT * FROM info WHERE title LIKE '%".$query."%' OR location LIKE '%".$query."%'OR qualification LIKE '%".$query."%' OR title,location LIKE '%".$query."%'";

它不会返回任何结果。 我希望它能通过标题和位置从数据库中获取数据。

完整查询看起来像这样

<?php
//error_reporting(0);
                    require_once('inc/config.php');
                    $con = mysqli_connect($host,$user,$pass, $db) or die ('Cannot connect :'.mysqli_error());
                    $query = $_GET['query'];
                    //$sql = "select * from info where title = '$title'";
                    $sql = "SELECT * FROM info WHERE '%".$query."%' OR location LIKE '%".$query."%'OR qualification LIKE '%".$query."%' OR CONCAT(title,location) LIKE '%".$query."%'";
                    mysqli_query($con, $sql) or die ('Failed Query : '.mysqli_error($con));
                    $result = mysqli_query($con,$sql)  or die("Error: ".mysqli_error($con));
                    while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) )
                    {

                        echo "<tr>
                        <td width=297 align=center>" . $row['title'] . "</td>
                        <td width=369 align=center>" . $row['location'] . "</td>
                        <td width=226 align=center>" . $row['qualification'] . "</td>
                        <td width=226 align=center>" . $row['date_posted'] . "</td>
                        <td>
                           <a href=http://www.google.de>
                           <input type=submit value=View Detail name=B4 style=font-family: Tahoma; font-size: 10pt></br></p>
                            </a>
                        </td>
                    </tr>";
                    } 

?>

0 个答案:

没有答案