当前位置:网站首页>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";
}
边栏推荐
- 【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
- 使用 EMQX Cloud 实现物联网设备一机一密验证
- 【外刊】睡眠与减肥
- 20220702 how do programmers build knowledge systems?
- 将 EMQX Cloud 数据通过公网桥接到 AWS IoT
- [shutter] shutter opens a third-party application (url|launcher plug-in search and installation | url| launcher plug-in official example | open browser | open a third-party application)
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- 数学建模——图与网络模型及方法(一)
- Market Research - current market situation and future development trend of aircraft wireless intercom system
- 原生js添加样式的方法
猜你喜欢

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

Landingsite eband B1 smoke test case

#include errors detected. Please update your includePath.

Basic concepts of image and deep understanding of yuv/rgb

Dynamic memory allocation (malloc calloc realloc free)

The failure rate is as high as 80%. What should we do about digital transformation?

Official announcement! The golden decade of new programmers and developers was officially released

20220702 how do programmers build knowledge systems?

Perceptron model and Application
随机推荐
[micro service sentinel] rewrite Sentinel's interface blockexceptionhandler
Web侧防御指南
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
SimpleITK使用——3. 常见操作
Record the functions of sharing web pages on wechat, QQ and Weibo
Market Research - current market situation and future development trend of marine wet exhaust hose
Market Research - current situation and future development trend of marine clutch Market
From personal heroes to versatile developers, the era of programmer 3.0 is coming
540. Single element in ordered array
攻防世界pwn题:Recho
基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
The failure rate is as high as 80%. What should we do about digital transformation?
Market Research - current market situation and future development trend of third-party data platform
Micro service gateway selection, please accept my knees!
Introduction to database system Chapter 1 short answer questions - how was the final exam?
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
sql service 截取字符串