dpjs2005 2014-10-16 21:36
浏览 52
已采纳

Search.php来自链接

How do I display results from my Search.php page using a link on Index.php?

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

The above doesn't work and all countries are displayed in Search.php. Sorry i'm new to PHP and MySQL.

My link is on index.php and is to search and display on search.php. I have the following code on 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>

The form is as follows:

<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条回答 默认 最新

  • doutui2016 2014-10-16 21:41
    关注

    I began writing a SSCCE to answer your question, but I realized that I simply do not have enough information and still do not quite understand what you are asking.

    Do you have an HTML form on index.php with an action that causes it to be submitted to search.php? Or do you have a link or set of links which the user can click, and the link that is selected controls what the user sees when sent to search.php?

    Assuming you have a set of links on index.php that sends a GET request to your search.php page (as shown in your initial line of code ?country_select=spain), are you then using this specific request to query a database? Or are you working from a set of data that is stored in a variable/array on the search.php page?

    If you are submitting a form, it should look something like:

    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);
    ?>
    

    If you are using the option of multiple links, it may look something like this:

    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);
    ?>
    

    Again, I do not know how your data is stored/formatted, I do not know how exactly you wish to present the search to the user, and I do not know what you wish to do with the result. For a more accurate response, please give a more detailed description of the issue and desired results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度