如何使用此php脚本设置时间戳

时间:2014-03-13 14:29:28

标签: php html date timestamp

我有这个脚本。当我选择日期时,我会通过选择日期来获取数据,但我想将其设置为时间戳

<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
  From : <input type="text" name="d1" class="tcal" value="" /> 
  <input type="submit" value="Search">
</form>
<table id="resultTable" data-responsive="table" style="text-align: left; width: 400px;" border="1" cellspacing="0" cellpadding="4">
<thead>
<tr>
    <th> Birtday </th>
    <th> Name </th>
    <th> Gender </th>
</tr>
</thead>
<tbody>
  <?php
    include('connect.php');
    if (isset($_GET["d1"])) { $d1  = $_GET["d1"]; } else { $d1="0000-00-00"; }; 
    $result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
    $result->bindParam(':a', $d1);
    $result->execute();
    for($i=0; $row = $result->fetch(); $i++){
  ?>
<tr class="record">
  <td><?php echo $row['date']; ?></td>
  <td><?php echo $row['name']; ?></td>
  <td><?php echo $row['gender']; ?></td>
</tr>
<?php
  }
?>
</tbody>
</table>

我如何使用此脚本设置时间戳

2 个答案:

答案 0 :(得分:0)

只需使用date()即可将今天的日期作为d1输入字段的值显示:

<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
From : <input type="text" name="d1" class="tcal" value="<?php echo date("m/d/Y"); ?>" /> 
<input type="submit" value="Search">
</form>

答案 1 :(得分:0)

Ya日期 - 函数将提供您需要的所有信息。如果您没有使用它,或者只是您不熟悉PHP,请查看文档以查找正确的日期参数。

例如:

date("d.m.Y") //outputs: 13.03.2014
date("n.d.Y") //outputs: 3.13.2014
date("m.d.y") //outputs: 03.13.14

可以在此处找到整个文档:http://php.net/manual/en/function.date.php

EDIT ::

所以,如果我找对你,你正在寻找类似这样的东西:

        <select class="Calendar" id="cdate_Month_ID" >
        <option value="1" <?=(date('n')==1?'selected':'')?>>Jan</option>
        <option value="2" <?=(date('n')==2?'selected':'')?>>Feb</option>
        <option value="3" <?=(date('n')==3?'selected':'')?>>Mar</option>
        <option value="4" <?=(date('n')==4?'selected':'')?>>Apr</option>
        <option value="5" <?=(date('n')==5?'selected':'')?>>May</option>
        <option value="6" <?=(date('n')==6?'selected':'')?>>Jun</option>
        <option value="7" <?=(date('n')==7?'selected':'')?>>Jul</option>
        <option value="8" <?=(date('n')==8?'selected':'')?>>Aug</option>
        <option value="9" <?=(date('n')==9?'selected':'')?>>Sep</option>
        <option value="10" <?=(date('n')==10?'selected':'')?>>Oct</option>
        <option value="11" <?=(date('n')==11?'selected':'')?>>Nov</option>
        <option value="12" <?=(date('n')==12?'selected':'')?>>Dec</option>
    </select>


    <select class="Calendar" id="cdate_Day_ID" >
        <option <?=(date('d')==1?'selected':'')?>>1</option>
        <option <?=(date('d')==2?'selected':'')?>>2</option>
        <option <?=(date('d')==3?'selected':'')?>>3</option>
        <option <?=(date('d')==4?'selected':'')?>>4</option>
        <option <?=(date('d')==5?'selected':'')?>>5</option>
        <option <?=(date('d')==6?'selected':'')?>>6</option>
        <option <?=(date('d')==7?'selected':'')?>>7</option>
        <option <?=(date('d')==8?'selected':'')?>>8</option>
        <option <?=(date('d')==9?'selected':'')?>>9</option>
        <option <?=(date('d')==10?'selected':'')?>>10</option>
        <option <?=(date('d')==11?'selected':'')?>>11</option>
        <option <?=(date('d')==12?'selected':'')?>>12</option>
        <option <?=(date('d')==13?'selected':'')?>">13</option>
        <option <?=(date('d')==14?'selected':'')?>>14</option>
        <option <?=(date('d')==15?'selected':'')?>>15</option>
        <option <?=(date('d')==16?'selected':'')?>>16</option>
        <option <?=(date('d')==17?'selected':'')?>>17</option>
        <option <?=(date('d')==18?'selected':'')?>>18</option>
        <option <?=(date('d')==19?'selected':'')?>>19</option>
        <option <?=(date('d')==20?'selected':'')?>>20</option>
        <option <?=(date('d')==21?'selected':'')?>>21</option>
        <option <?=(date('d')==22?'selected':'')?>>22</option>
        <option <?=(date('d')==23?'selected':'')?>>23</option>
        <option <?=(date('d')==24?'selected':'')?>>24</option>
        <option <?=(date('d')==25?'selected':'')?>>25</option>
        <option <?=(date('d')==26?'selected':'')?>>26</option>
        <option <?=(date('d')==27?'selected':'')?>>27</option>
        <option <?=(date('d')==28?'selected':'')?>>28</option>
        <option <?=(date('d')==29?'selected':'')?>>29</option>
        <option <?=(date('d')==30?'selected':'')?>>30</option>
        <option <?=(date('d')==31?'selected':'')?>>31</option>
    </select>

    <input class="Calendar" type="text" size="4" maxlength="4" title="Year" value="<?=date('Y'?>">