简体   繁体   English

如何将date_from和date_to从一个php传递到另一个php以进行数据库查询

[英]How to pass date_from and date_to from one php to another one to do a db query

I use a jquery ui calendar let user choose the start and end date, click a link in first php page to do a mydql query in second php page to export the query result as a download csv file (some guys said it's impossible to do this in one page, it have to be two php pages). 我使用jquery ui日历让用户选择开始日期和结束日期,单击第一个php页面中的链接以在第二个php页面中执行mydql查询,以将查询结果导出为下载的csv文件(有些人说这样做是不可能的)在一页中,必须是两个php页)。

My question is how to pass $date_from and $date_to from first php and how to get those value in second page. 我的问题是如何从第一个php传递$ date_from和$ date_to以及如何在第二个页面中获取这些值。

thx 谢谢

this works! 这可行! query string like this: check.php?date_from=2012-09-01&date_to=2012-09-30 像这样的查询字符串:check.php?date_from = 2012-09-01&date_to = 2012-09-30

and in check.php, the value can get like this: 在check.php中,值可以像这样:

$export_type = $_GET['export_type'];
$date_from = $_GET['date_from'];
$date_to = $_GET['date_to'];

In your html form you can set an element with a 'name' attribute and value of the $date_from variable and pass it to another page like: 在您的html表单中,您可以设置一个具有'name'属性和$date_from变量值的元素,并将其传递给另一个页面,例如:

<form action="next_page.php" method="post">
<input type="text" name="text_name" value=<?= $date_from ?> />
</form>

In next_page.php you can access it with the $_POST variable: 在next_page.php中,您可以使用$ _POST变量进行访问:

<? echo $_POST['text_name'] ?>

You can do this with Ajax on one page. 您可以使用Ajax在一页上执行此操作。 You can do this on one page with only one page refresh, too. 您也可以只刷新一页就在一页上执行此操作。 There are several ways to do this. 有几种方法可以做到这一点。 One way I can think of off the top of my head would be to accept the data from the javascript calendar via a "submit" button in a form (that is also populated with the data from your javascript calendar). 我可以想到的一种方法是通过表单中的“提交”按钮(也填充有您的JavaScript日历中的数据)接受javascript日历中的数据。 Something like this: 像这样:

page.php: page.php:

<?php
  if(isset($_POST['formsubmit'])) {
    grab_form_data();
  }
?>
<html>...<body>
...
<script type="text/javascript">
  jquery_calendar();
  populates_form_field1_below_on_select();
</script>
...
<form method="POST" action="page.php">
<input id="field1" name="field1"></input>
<input type="submit" name="submit" value="submit"></input>
</form>
<?php
  create_csv_download_link_from_PHP_data_at_top_of_page();
?>
...
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM