【问题标题】:Display output result in another page in PHP在 PHP 的另一个页面中显示输出结果
【发布时间】:2014-08-18 13:47:50
【问题描述】:

我有一个旅游搜索应用程序,用户可以在其中根据三个不同的参数(地区、国家和时长)搜索可用的旅游。目前我正在使用的代码在同一页面中显示输出结果。我希望输出结果显示在不同的页面中。

下面是我的 PHP 代码:

<?php
      mysql_connect("localhost", "root", "");
    mysql_select_db("byp");

    if(isset($_POST['submit'])){
        $region=$_POST['region'];
        $country=$_POST['country'];
        $duration=$_POST['duration'];

        //define the index for the All option
        $optionAllValue = 0; //add here the option index value used for the 'All' option
        //define the where clause for the query
        //in order to avoid many conditions verifications, we start it as 1=1
        $whereClause = "1=1";

        //now we check if the option selected for each field is not the value defined for the option 'All'
        //this is just an example, and the best would be to create a function to avoid the replication of code 
        if($region != $optionAllValue)
        {
            $whereClause = $whereClause." and region='$region'";
        }
        if($country != $optionAllValue)
        {
            $whereClause = $whereClause." and country='$country'";
        }
        if($duration != $optionAllValue)
        {
            $whereClause = $whereClause." and duration='$duration'";
        }

        $query = "select * from byp_tour where ".$whereClause;

        //original query select * from byp_tour where region='$region' and country='$country' and duration='$duration'"
        $tour = mysql_query($query);
        $tourNum = mysql_num_rows($tour);

        if($tourNum >0){

            while($result=mysql_fetch_array($tour)){

                $tour_name = $result['tour_name'];
                $tour_detail = $result['tour_detail'];

                echo "Tour Name: $tour_name";  // HERE IS THE OUTPUT RESULT
                echo "<br />";
                echo "Tour Detail: $tour_detail";
                echo "<br />";
                echo "<br />";
                echo "<br />";
            }
        }
        else{
            echo "No Tour Found";
            echo "<br />";
            echo "<br />";
        }
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <title>BYP Test</title>
    </head>
    <body>
        <form action="searchtest.php" method="post">
            <div>
                <label>Region</label>
                <select id="region" name="region">
                    <option value="0">All</option>
                    <option value="1">South East Asia</option>
                    <option value="2">Africa</option>
                    <option value="3">Europe</option>
                    <option value="4">America</option>
                    <option value="5">Australia</option>                               
                </select>
            </div>
            <div>
                <label>Country</label>
                <select id="country" name="country">
                <option value="0">All</option>
                <option value="1">Cambodia</option>
                <option value="2">Thailand</option>
                <option value="3">Vietnam</option>
                <option value="4">Myanmar</option>
                <option value="5">Laos</option>
                <option value="6">Ethiopia</option>
                <option value="7">France</option>
                <option value="8">New York City</option>
                <option value="9">Melbourne</option>
            </select>
        </div>
        <div>
            <label>Duration</label>
            <select id="duration" name="duration">
                <option value="0">All</option>
                <option value="1">5 Days</option>
                <option value="2">10 Days</option>
            </select>
        </div>
        <input type="submit" name="submit" value="submit" />
        </form>
    </body>
</html>

【问题讨论】:

  • 你希望我们...?
  • 图片:404-未找到...
  • 注意:您正在使用的 mysql_* 函数正在被弃用,并将从未来的 PHP 版本中删除。您不应该使用它们编写新代码,而是使用 mysqli_* 或 PDO。
  • 我想获得有关可以在另一个页面中回显结果的确切代码的帮助。

标签: php mysql


【解决方案1】:

你需要将target="_blank"添加到&lt;form&gt;:

<form action="searchtest.php" method="post" target="_blank">

【讨论】:

  • 谢谢我得到了解决方案。我已将 PHP 代码放在另一个文件 show_result.php 中。我修改了这一行&lt;form action="show_result.php" method="post" target="_blank"&gt;
猜你喜欢
  • 1970-01-01
  • 2018-03-13
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 2018-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多