gpt4 book ai didi

PHP Sum 状态栏

转载 作者:行者123 更新时间:2023-11-29 07:06:03 26 4
gpt4 key购买 nike

我有一个 php 脚本,我试图将状态类型汇总到变量中。例如,当我执行以下操作时:

echo $val['status'];

我得到:

New New New Dead In Process New New New New New Dead New Dead Dead New New New In Process

我想要做的是将所有这些按状态类型汇总并将它们放入变量中:

$statusnew
$statusdead
$statusinprocess

所以如果我要做:

echo $statusnew;

我会看到“12”等等。我对 PHP 非常陌生,所以我想找出最有效的方法来做到这一点。我知道有一个 array_sum 函数,但不确定它是否适用于此处,因为我们没有对数值求和。

循环:

if($_SESSION['partner'] == 1)
{


$query = "select l.id as lead_id , l.account_name as account_name , l.first_name as first_name , l.last_name as last_name,l.date_entered as date_entered , lc.endpoints_c as endpoints , l.status as status from leads as l
join leads_cstm as lc on lc.id_c = l.id
where lc.account_id_c = '".$_SESSION['account_id']."'
and l.deleted = '0' and l.status <> 'Converted' order by date_entered DESC";


$db -> PS_Pagination($query, 20, 5, "");
$db -> setDebug(true);
$rs = $db->paginate();
$num_rows = mysql_num_rows($rs);

在脚本的更下方:

        while($val = mysql_fetch_assoc($rs)) 
{
$date_create = date("m/d/Y", strtotime($val['date_entered']));

我刚刚从@Joseph 添加的内容:

        $count = array(); // for graph

// then, in your loop:
if ( array_key_exists($val['status'], $count) )
$count[$val['status']]++;
else
$count[$val['status']] = 1;

echo $count['New'];

最佳答案

$count = array();

while($val = mysql_fetch_assoc($rs))
{
$date_create = date("m/d/Y", strtotime($val['date_entered']));

if ( array_key_exists($val['status'], $count) )
$count[$val['status']]++;
else
$count[$val['status']] = 1;

// continue with everything else being done in this loop
}

运行循环后,您可以像这样访问计数:

$count['new']; // 12
$count['dead']; // 4
$count['in proccess']; // 2

关于PHP Sum 状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7197015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com