【发布时间】:2014-06-28 09:09:16
【问题描述】:
下面有一个 HTML 搜索表单。
我需要一些关于我的 PHP 和 MySQL 的帮助。我还是 PHP 和 MySQL 的新手,一位朋友告诉我我需要使用 WHERE 语句,但在我所做的研究中,它向我表明不是这样,或者我理解错了。由于我正忙于一个项目,我非常需要这个:
<form id="advanced_search" action="" class="clearfix" name="advanced_search" method="post">
这是所有标签和文本字段,其中一些是您可以看到的选择字段:
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="country"><b>Country</b></label>
<input type="text" name="country"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="location"><b>Location</b></label>
<input type="text" name="location"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="status"><b>Status</b></label>
<input type="radio" name="status" value="For Rent"><b><span style="color: #0A0000">For Rent</span></b></input><br />
<input type="radio" name="status" value="For Sale"><b><span style="color: #0A0000">For Sale</span></b></input>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="type"><b>Type</b></label>
<input type="text" name="type"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="bedrooms"><b>Bedrooms</b></label>
<input type="text" name="bedrooms"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="baths"><b>Bathrooms</b></label>
<input type="text" name="baths"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="min_price"><b>Min Price</b></label>
<input type="text" name="minprice"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="max_price"><b>Max Price</b></label>
<input type="text" name="maxprice"><br /><br />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="condition"><b>Condition of Use</b></label>
<input type="radio" name="condition" value="Furnished"><b><span style="color: #0A0000">Furnished</span></b></input><br />
<input type="radio" name="condition" value="Not Furnished"><b><span style="color: #0A0000">Not Furnished</span></b></input>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<label for="from"><b>From The</b></label>
<input type="radio" name="from" value="Agent"><b><span style="color: #0A0000">Agent</span></b></input><br />
<input type="radio" name="from" value="Private"><b><span style="color: #0A0000">Private</span></b></input>
</div>
这是表单的结尾,但我看到这里没有提交值:
<div class="clearfix"></div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="btn btn-inverse btnblock">SEARCHPROPERTY</a>
</div>
</form>
**Here's my PHP I just have done:**
<?php
if(isset($_POST['search']))
{
$key=$_POST["search"]; //key=pattern to be searched
$con=mysqli_connect("saproperties","localhost"," ","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
**Here by the WHERE and the LIKE, What do I have to put in there?**
$result=mysqli_query($con,"select * from properties where `column_name` like '%$key%'");
while($row=mysqli_fetch_assoc($result))
{
我在这里输入了我的价值观:
$country = $_POST['country'];
$location = $_POST['location'];
$status = $_POST['status'];
$type = $_POST['type'];
$bedrooms = $_POST['bedrooms'];
$bathrooms = $_POST['bathrooms'];
$minprice = $_POST['min_price'];
$maxprice = $_POST['max_price'];
$conditionofuse = $_POST['conditionofuse'];
$fromthe = $_POST['fromthe'];
}
}
?>
【问题讨论】:
-
我没有看到任何 PHP 代码
-
我需要php代码,因为我不明白该怎么做
-
我还是 PHP 新手
-
你有数据库吗?你有一个启用了 PHP 的网络服务器吗?您是否看过这个新奇的互联网事物上存在的数百万关于 PHP 和数据库的教程?
-
看看stackoverflow.com/questions/18542402/…>这是一篇关于如何做到这一点的好文章。