Search.php来自链接

时间:2014-10-16 21:36:29

标签: php mysql

如何使用Index.php上的链接显示我的Search.php页面的结果?

<a href="search.php?country_select=spain">Spain</a>

以上操作无效,所有国家/地区都显示在Search.php中。对不起,我是PHP和MySQL的新手。

我的链接在index.php上,是搜索并显示在search.php上。我在search.php上有以下代码:

<?php $appmt = $bsiCore->ClearInput(base64_decode($_REQUEST['appmt_id']));
$apartDetails = $bsiCore->getApartmentdetails($rowappt['appmt_id']);
$featuresarr = $bsiCore->getApmtFeatures($rowappt['appmt_id']);
?>

<div class="col-md-4 col-sm-6 single listing">


    <div class="offer offer-wrap">
    <img class="img-responsive" src="<?php echo ($rowappt['default_img']=="")? "http://www.placehold.it/800x450/ddd/bbb&amp;text=Image":"gallery/ApartImage/".$rowappt['default_img']; ?>" alt="">
    <span class="label label-info">
    <?php echo $rowappt['country']; ?>
    </span>

    <div class="btn-group">
      <a href="<?php echo str_replace(" ","-",strtolower(trim($rowappt['appmt_name'])))."-".$rowappt['appmt_id'].".html"; ?>"><button class="btn btn-success btn-sm" type="button">Details</button>
        <button class="btn btn-default btn-sm" type="button"><em class="icon-info-sign"></em></button></a>
      </div>
    <div class="padding img1">
    <h2 class="text-center text-info"><?php echo $rowappt['city']; ?></h2>
      <h4 class="text-center"><?php echo $rowappt['bedroom']; ?> bedroom, <?php echo $rowappt['bathroom']; ?> bathroom</h4>

      <span class="label2 label-info">
    <?php echo $bsiCore->config['conf_currency_symbol'].$rowappt['price']; ?><span>p/w*
    </span>
    </div>
    </div>
</div>

表格如下:

<form action="search.php" class="form-inline reservation-horizontal clearfix" role="form" method="post" name="form1" id="form1" style="padding-bottom:0px">  

        <div class="row">
            <div class="col-lg-12" style="min-height: 60px; background-color: rgba(255, 255, 255, 0.4);  border-radius: 5px;">

                    <div class="pad1 col-md-2 col-sm-3 col-xs-12">
                    <select name="country_select"  id="drop_1">

  <option value="" selected="selected">All Countries</option>
</select> 
 </div>              

            <div>

            <div class="pad1 col-md-2 col-sm-3 col-xs-12">
            <select name="country_select">

  <option value="" selected="selected" disabled="disabled">Any City / Town</option>

</select> </div></div>

                <div class="pad1 col-md-2 col-sm-3 col-xs-12">
                    <select id="appartment_type" name="appartment_type">
              <?php echo $bsiCore->getApmtTypeCombobox();?>
            </select>
            </div>



            <div class="pad1 col-md-2 col-sm-3 col-xs-12">
            <select name="bathroom" id="bathroom" >
                <option value="">Sleeps</option>
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="See Description">16+</option>
                </select>
            </div>

            <div class="pad1 col-md-2 col-sm-3 col-xs-12">
                <button value="Search" class="btn btn-success" style="width: 100%;">Search</button>
           </div>  

           </div> 

            </div>
        </div>
        </form>

2 个答案:

答案 0 :(得分:1)

我开始写一个SSCCE来回答你的问题,但我意识到我根本没有足够的信息,但仍然不太明白你在问什么。

您是否在index.php上有一个HTML表单,其中的操作会将其提交给search.php?或者,您是否有用户可以点击的链接或一组链接,并且所选的链接控制用户在发送到search.php时看到的内容?

假设您在index.php上有一组向GET页面发送search.php请求的链接(如您的初始代码行?country_select=spain所示),然后你使用这个特定的请求来查询数据库?或者您是使用存储在search.php页面上的变量/数组中的一组数据吗?

如果您要提交表单,它应该类似于:

index.php

<form method="post" action="search.php">
  <label>Select Country:</label><br>
  <input type="text" id="country"><br>
  <input type="submit" value="Submit">
</form>

search.php

<?php 
$country=$_POST['country'];
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$query = "SELECT * FROM `country_table` WHERE `country_name`= '".$country."'";
mysqli_query($con, $query);
?>

如果您使用多个链接选项,它可能如下所示:

index.php

<p>Please select a country</p><br>
<a href="search.php?country_select=spain">Spain</a><br>
<a href="search.php?country_select=united+states">United States</a><br>
<a href="search.php?country_select=italy">Italy</a><br>

search.php

<?php
$country=$_GET['country_select'];
$con = mysqli_connect("localhost","my_user","my_password","my_db");
$query = "SELECT * FROM `country_table` WHERE `country_name`= '".$country."'";
mysqli_query($con,$query);
?>

同样,我不知道您的数据是如何存储/格式化的,我不知道您希望如何向用户呈现搜索,我不知道您希望如何处理结果。如需更准确的回复,请详细说明问题和预期结果。

答案 1 :(得分:0)

确保&#34; country_select&#34;在您的PHP接收代码中为&#34; $ _ REQUEST [&#39; country_select&#39;];&#34;。否则,它可能是search.php文件的解析端的问题。处理MySQL查询时也可能是一个问题。