当前位置:网站首页>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";
}
边栏推荐
- [C question set] of V
- 100 important knowledge points that SQL must master: using cursors
- Record the functions of sharing web pages on wechat, QQ and Weibo
- [shutter] shutter gesture interaction (small ball following the movement of fingers)
- Market Research - current situation and future development trend of carob chocolate market
- 数据库系统概论第一章简答题-期末考得怎么样?
- Task and privilege level protection
- The difference between include < > and include ""
- Les trois principaux points de douleur traités par servicemesh
- What is it that makes you tremble? Those without fans can learn
猜你喜欢

Task and privilege level protection

《Just because》阅读感受

"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba

腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?

Based on asp Net (used mobile phone sales management system) +asp Net+c # language +vs2010+ database can be used for course design and post design learning

【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)

Perceptron model and Application
![[shutter] shutter application theme (themedata | dynamic modification theme)](/img/77/6b0082368943aee7108ac550141f28.gif)
[shutter] shutter application theme (themedata | dynamic modification theme)

建立自己的网站(22)

任务和特权级保护
随机推荐
开发者分享 | HLS, 巧用AXI_master总线接口指令的定制并提升数据带宽-面积换速度...
分享一下如何制作专业的手绘电子地图
[QT] Q multithreaded development - Analysis of multithreaded application examples (Mandelbrot)
php优化foreach中的sql查询
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
LightGBM原理及天文数据中的应用
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
540. Single element in ordered array
ServiceMesh主要解决的三大痛点
【AUTOSAR-DCM】-4.3-UDS $22和$2E服务如何读取和写入NVM数据
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
对象与对象变量
Unity发布WebGL播放声音的一种方法
Destroy in beforedestroy invalid value in localstorage
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
Promise optimized callback hell
Market Research - current market situation and future development trend of handheld wound imaging equipment
Notes on key vocabulary in the English original of the biography of jobs (11) [chapter nine]
基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
Market Research - current market situation and future development trend of aircraft front wheel steering system