php 使用 NOT 运算符评估条件
P粉618358260
P粉618358260 2024-04-02 09:57:41
0
1
397

我有 4 个销售办事处,一旦所有 4 个销售办事处均收到 20 个销售线索,则只有 4 号销售办事处应该收到当天剩余的销售线索。我需要一些帮助来创建条件,以基本上检查销售办公室 1-4 是否均已收到 20 个潜在客户,然后显然按照说明继续进行

首先,我查询数据库来检查我的计数器(是的,我知道这可以更紧凑,并且可以在循环内完成)

$sales_office= 1;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office1_count = $result['LeadsReceivedToday'];

$sales_office= 2;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office2_count = $result['LeadsReceivedToday'];

$sales_office= 3;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office3_count = $result['LeadsReceivedToday'];

$sales_office= 4;
$sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
$sql->execute([$sales_office]);
$result = $sql->fetch();
$sales_office4_count = $result['LeadsReceivedToday'];

当我执行这个逻辑时,它没有按预期工作?一旦 sales_office = 1 达到 20 个销售线索,它就会直接转移到销售办公室 4?

if ($sales_office1_count != 20 && $sales_office2_count != 20 && $sales_office3_count != 20)
{
    //distribute leads to sales office 1-4 in order of 1-4
    
}
else
{
   //only send leads to sales office no 4
}

P粉618358260
P粉618358260

全部回复(1)
P粉792673958

您当前对所有办公室计数的逻辑检查,您必须分别检查每个办公室。

if ($sales_office1_count 

此外,您可以通过使用数组来提高代码的可读性:

$officesLeadsCount = [1 => 0, 2 => 0, 3 => 0, 4 => 0];

foreach ($officesLeadsCount as $number => $value) {
  $sql = $conn->prepare("SELECT LeadsReceivedToday FROM Lead_Counter WHERE SalesOffice=?");
  $sql->execute([$number]);
  $result = $sql->fetch();
  $officesLeadsCount[$number] = $result['LeadsReceivedToday'];    
}


if ($officesLeadsCount[1] 
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!