PHP的回声结果 [英] PHP echo result

查看:65
本文介绍了PHP的回声结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何在另一个页面上回显以下结果.我需要它来回应用户选择的内容.

How would i echo the following result on another page. I need it to echo what the user selects.

<strong>Return</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($return as $return) { ?>
        <option value="<?php echo $return; ?>"><?php echo $return; ?></option>
    <?php } ?>

谢谢

用户选择位置的完整代码.他们在此页面上选择的信息就是我想要在另一页面上回显的信息.

Full code of where the user makes a selection. The information they select on this page is what i would like echoed on another page.

<!DOCTYPE html>
<?php
session_start();
?>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <title>
        </title>
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <link rel="stylesheet" href="my.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
        </script>
        <script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
        </script>
        <script src="my.js">
        </script>
        <!-- User-generated css -->
        <style>
        </style>
        <!-- User-generated js -->
        <script>
            try {

    $(function() {

    });

  } catch (error) {
    console.error("Your javascript has an error: " + error);
  }
        </script>
     </head>
    <body>
        <!-- Home -->
        <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
            <a data-role="button" data-theme="d" href="login.html" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
                    Back
                </a>
                <a data-role="button" href="index.html" data-icon="home" data-iconpos="right" data-theme="d"class="ui-btn-right">
                 Home  
                </a>
                <h3>
                    Book Car
                </h3>
           </div>

           <div data-role="content">
                <h3>
                    Select date/time:
                </h3>
                <br />
<?php
{
    mysql_connect("localhost" , "" , "") or die (mysql_error());
    mysql_select_db("") or die(mysql_error());

    $query = "SELECT `book_time`, `book_date`, `return_time`, `return_date` FROM `Rental`";

    //executes query on the database
    $result = mysql_query ($query) or die ("didn't query");

    //this selects the results as rows
    $num = mysql_num_rows ($result);    

    $return = array();
    $rent = array();
    while($row=mysql_fetch_assoc($result))
    {

        $rent[] = $row['book_date'].' '.$row['book_time'];
        $return[] = $row['return_date'].' '.$row['return_time'];
    }
}
?>      

    <form method="post" action="car.php">
    <strong>Rent out</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($rent as $rent) { ?>
        <option value="<?php echo $rent; ?>"><?php echo $rent; ?></option>
    <?php } ?>

    </select>
    <br />

    <strong>Return</strong>            
    <select id="Date" name="Date">                      
    <option value="0">--Select date/time--</option>
    <?php  foreach ($return as $return) { ?>
        <option value="<?php echo $return; ?>"><?php echo $return; ?></option>
    <?php } ?>


    </select>

                <br />
                <br />

                <input type="submit" name="Submit" value="Book" />
            </form>

             </div>
        </div>
    </body>
</html>

推荐答案

表单基础101:

~~~index.php~~~
<form action='the_new_page.php' method='POST'>
  <input type='text' name='first_thing'>
  <input type='hidden' name='some_hidden_guy' value='1'>
  <input type='submit' name='submit_button' value='submit'>
</form>

用户提交上述表单时,浏览器会将其定向到 the_new_page.php ,而 the_new_page.php 将了解所有表单信息.

When a user submits the above form, the browser will direct them to the_new_page.php, and the_new_page.php will know all of the form information.

表格传递名称 value ,而您所需要知道的只是这些. id 纯粹是出于html的目的,并且在HTML中,通常,您不允许有多个具有相同ID的元素.人们通常会混淆地将表单字段的ID命名为与表单字段的名称"相同,这使得学习每种表单的含义变得非常困难.

Forms pass the name and the value, nothing else for as what you need to know. id is PURELY for html purposes, and as a rule in HTML, you are not allowed to have more than one element with the same ID. People usually confusingly name the id of the form field the same as the "name" of the form field, which makes learning what each means pretty difficult.

因此,提交表单后,它将进入第二页,然后您可以执行以下操作:

Thus, after submitting the form it will then go to your second page and then you can do:

~~~the_new_page.php~~~
//You can then do
echo $_POST['some_hidden_guy'] //will be 1
echo $_POST['first_thing'] //Will be whatever you inserted into the text box

如果您希望表单返回到您当前所在的页面,只需将 action 留为空白,或者为< form action =''> < form method ='POST'>

If you want the form to go back to the current page you're on, you simply leave the action blank, either as <form action=''> or <form method='POST'>

在多个页面上保留相同的信息!

Persisting the same information for multiple pages!

现在,这不是编程人员执行此操作的方法,因为您应该找到一种不必在任何页面上重复相同代码的方法.如果您不这样做,我现在警告您.此应用程序的维护将成为一场噩梦,因为您每次要添加新字段时都必须编辑每个页面.转到示例.

Now, this is a very not programmer way to do this, as you should find a way to not have to repeat the same code on ever page. If you do not, and I'm warning you now.. maintenance of this app will become a nightmare as you'll have to edit every single page every single time you want to add a new field. On to the example.

现在,假设您已将信息传递给car.php,现在您想在carplan.php上使用它.

Now, say you passed information to car.php and you now want to use it on carplan.php.

~~~car.php~~~
    <form action='carplan.php' method='GET or POST, whichever it is you be using using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <option name='plan_id'>
            <?php foreach($plans as $plan): ?>
                <select value='<?php echo $plan['id'] ?>'><?php echo $plan['name'] ?>'>
            <?php endforeach; ?>
        </option>
        <input type='submit' name='submit' value='Get That Plan'>
    </form>

最后在carplan.php上

And finally on carplan.php

    ~~~carplan.php~~~
    <form action='the_next_step.php' method='GET or POST, whichever you be using'>
        <input type='hidden' name='Date' value='<?php echo $_GET['date'] ?>'>
        <input type='hidden' name='some_other_thing' value='<?php echo $_GET['some_other_thing'] ?>'>
        <input type='hidden' name='plan_id' value='<?php echo $_GET['plan_id']?>'>
        <input type='submit' name='submit' value='The next step!'>
    </form>

这篇关于PHP的回声结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆