当前位置:网站首页>PHP implements querying the data matching the date of birth according to the entered age
PHP implements querying the data matching the date of birth according to the entered age
2022-07-02 22:39:00 【If time comes again】
Requirements describe : The front end sends requests such as 33-55 year , After getting the age data, the backend converts the specified age into date
$search = $_POST;
$year = date('Y');
$month = date('m');
$day = date('d');
$max_birth = '';
$min_birth = '';
// The user entered the minimum age and maximum age
if(isset($search['person_age_min']) && isset($search['person_age_max'])){
$min = min($search['person_age_min'], $search['person_age_max']);
$max = max($search['person_age_min'], $search['person_age_max']);
# Calculate the earliest date of birth for the maximum age
$max_year = $year - $max - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# Calculate the last date of birth for the minimum age
$min_year = $year-$min;
$min_birth = $min_year.'-'.$month.'-'.$day;
}elseif(isset($search['person_age_min']) && !isset($search['person_age_max'])){ // The user only entered the minimum age
# Calculate the earliest date of birth for the maximum age
$max_year = $year - $search['person_age_min'] - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# Calculate the last date of birth for the minimum age
$min_year = $year-$search['person_age_min'];
$min_birth = $min_year.'-'.$month.'-'.$day;
}elseif(!isset($search['person_age_min']) && isset($search['person_age_max'])) { // The user only entered the maximum age
# Calculate the earliest date of birth for the maximum age
$max_year = $year - $search['person_age_max'] - 1;
$max_birth = date('Y-m-d', strtotime("+1 day", strtotime($max_year.'-'.$month.'-'.$day)));
# Calculate the last date of birth for the minimum age
$min_year = $year-$search['person_age_min'];
$min_birth = $min_year.'-'.$month.'-'.$day;
}
if(!empty($min_birth) && !empty($max_birth)){
// sql sentence
$sql = "select * from user where birth between $max_birth and $min_birth";
}
边栏推荐
- Leetcode circular linked list (fast and slow pointer) code line by line interpretation
- Web侧防御指南
- New feature of go1.18: trylock, which has been tossed n times
- Destroy in beforedestroy invalid value in localstorage
- Market Research - current situation and future development trend of carob chocolate market
- scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
- Market Research - current situation and future development trend of marine clutch Market
- 【微服务|Sentinel】重写sentinel的接口BlockExceptionHandler
- Pointer array parameter passing, pointer parameter passing
- C语言,实现三子棋小游戏
猜你喜欢
Simpleitk use - 4 Strange question
Ransack组合条件搜索实现
The difference between include < > and include ""
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
Hanoi Tower problem
情感计算与理解研究发展概述
C language, to achieve three chess games
[staff] Sibelius 7.5.1 score software installation (software download | software installation)
任务和特权级保护
From "bronze" to "King", there are three secrets of enterprise digitalization
随机推荐
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
UE4 游戏架构 学习笔记
php实现根据输入的年龄查询出生日期符合的数据
[shutter] shutter gesture interaction (small ball following the movement of fingers)
APP页面分享口令Rails实现
对象与对象变量
ServiceMesh主要解决的三大痛点
New feature of go1.18: trylock, which has been tossed n times
Introduction to database system Chapter 1 short answer questions - how was the final exam?
Web side defense Guide
An overview of the development of affective computing and understanding research
From personal heroes to versatile developers, the era of programmer 3.0 is coming
Get off work on time! Episode 6 of Excel Collection - how to split and count document amounts
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
Unity3d learning notes 4 - create mesh advanced interface
UE4 UI自适应屏幕
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
Infrastructure is code: a change is coming
Market Research - current situation and future development trend of herringbone gear Market
Dynamic memory allocation (malloc calloc realloc free)