如何检查BBDD中的任何范围之间的两个数字范围是否? php
我的问题是:
我在数据库2个字段中,称为“ min_amount”和“ max_amount”,它们之间形成了一系列数字。
例如:最小值:0和最大:1000
我要做的是检查在插入新范围之前,它是否在另一个现有范围之间。
目前,我有这样的事情:
foreach ($ranges as $range){ // $range is every row in table
$min = $range[0]; //the min value of BBDD row
$max = $range[1]; // the max value of BBDD row
$imin = $input["min_amount"]; // My min value I want to insert
$imax = $input["max_amount"]; // My max value I want to insert
if ($imin < $max || $imax > $min){
$inrange = true;
}
}
您将如何解决这个问题?谢谢。
My question is the following:
I have in database 2 fields called "min_amount" and "max_amount" and between them they form a range of numbers.
For example: min: 0 and max: 1000
What I am trying to do is to check if, before inserting a new range, it is between another existing range.
At the moment I have something like this:
foreach ($ranges as $range){ // $range is every row in table
$min = $range[0]; //the min value of BBDD row
$max = $range[1]; // the max value of BBDD row
$imin = $input["min_amount"]; // My min value I want to insert
$imax = $input["max_amount"]; // My max value I want to insert
if ($imin < $max || $imax > $min){
$inrange = true;
}
}
How would you solve this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您正在尝试检查所有现有范围的新范围。在这种情况下,您可以获得所有现有范围的最高最小值和最低值,并将它们与您的新范围进行比较:
It looks like you are trying to check the new range against all the existing ranges. In that case you can get the highest min value and the lowest max value of all the existing ranges and compare them against your new range: