需要帮助。 我正在准备一个搜索表单。在选择查询中需要帮助 我可以在表格的所有列中搜索“构建”单词 以下是我试过的查询。
$search = $_POST['search'];
$sql = mysql_query("SELECT * FROM property WHERE posthead,requestto,ptype,requestby,owner,bed,bath,price,sqft,descp = '".$search."'");
$result = (mysql_fetch_array($sql));
echo "Post Head : ". $result['posthead']."<br />";
echo "Request To : ". $result['requestto']."<br />";
echo "Type : ". $result['ptype']."<br />";
echo "Request By : ". $result['requestby']."<br />";
echo "Owner : ". $result['owner']."<br />";
echo "Bed : ". $result['bed']."<br />";
echo "Bath : ". $result['bath']."<br />";
echo "Price : ". $result['price']."<br />";
echo "Sq ft. : ". $result['sqft']."<br />";
echo "Description : ". $result['descp']."<br />";
答案 0 :(得分:2)
$sql = mysql_query("SELECT * FROM property WHERE posthead = '".$search."' OR requestto= '".$search."' OR ptype= '".$search."' OR requestby = '".$search."' OR owner= '".$search."' OR bed = '".$search."' OR bath= '".$search."' OR price= '".$search."' OR sqft,descp = '".$search."'");
并将$result = (mysql_fetch_array($sql));
更改为$result = (mysql_fetch_assoc($sql));
注意:
答案 1 :(得分:1)
尝试:
最好使用 "CONCAT"
作为列:
$ sql = mysql_query(“SELECT * FROM property WHERE CONCAT(posthead,requestto,p型,requestby,主人,床,浴缸,价格,平方英尺,descp) 喜欢“%。$ search。”%'“);
OR
可以使用,但 CONCAT
可以减少查询大小。
答案 2 :(得分:0)
尝试SELECT * FROM property WHERE posthead = $search OR requestto = $search ...
等
答案 3 :(得分:0)
由于您正在创建搜索表单,因此您可能希望能够通过部分匹配而不是确切的单词来查找记录。为此,您可以使用LIKE
$q = "SELECT * FROM property
WHERE posthead LIKE '%$search%' OR
requestto LIKE '%$search%' OR
ptype LIKE '%$search%' OR
requestby LIKE '%$search%' OR
owner LIKE '%$search%' OR
bed LIKE '%$search%' OR
bath LIKE '%$search%' OR
price LIKE '%$search%' OR
sqft LIKE '%$search%' OR
descp LIKE '%$search%'";
$sql = mysql_query($q);