从option中 获取到某年的值
2011~2020mysql是时间戳格式,请问 怎么截取值中的全年时间戳?

解决方案 »

  1.   

    我知道用strtotime()转换成时间戳
    但是 我的sql语句怎么写啊??
    这个转换的只是一个时间戳,但是 我想获得的是一整年。。?
      

  2.   

    是要查询 option选择要查询哪年的
    选择后 会给后台一个值
    比如是2011
    到后台后 strtotime()可以把2011选换成时间戳
    但是 怎么从数据库里面读出2011年所有记录?就是从2011年初到年末的所有值
    数据库里面 也是时间戳格式
      

  3.   


    时间戳直接比较select xxxx from xxxx where  xxx <endtime and xxx >startime.
      

  4.   

    select * from tbl_name where FROM_UNIXTIME(字段,'%Y')='$year'
      

  5.   

    前台<form action="1.php" method="post">
    <select name="radio">
    <option value="all">全部时间</option>
    <?php
    for($i=2011;$i<=2030;$i++)
    {
    ?>
    <option value="<?=$i?>"><?=$i?></option>
    <?php
    }
    ?>
    </select>
    <input type="submit" value="提交" />
    </form>
    后台<?php
    $radion=$_POST["radio"];
    if($radion=="all")
    {
    echo "全部时间";
    }
    else
    {
    $timeall=strtotime($radion);
    echo $timeall;
    $where_string="select * from tbs_index_affiche where FROM_UNIXTIME(addDateTime,'%Y')='$timeall'";
    }
    ?>
    mysql的时间戳存在addDateTime中
    不是很了解FORM_UNIXTIME语句,这个语句显示不出来啊。。
      

  6.   


    $begintimeall=$radio."-01-01";
    $endtimeall=$radio."-12-31";strtotime($begintimeall);
    strtotime($endtimeall);
    "where name between 起始时间 and 结束时间;
      

  7.   

    select * from tbl_name where 字段 like '$year%'
      

  8.   

    时间戳,不是时间格式,所以like '$year'是行不通的。
    推荐版主的from_unixtime()这种方法。