Welcome Guest, Not a member yet? Register   Sign In
Conditional style for specific data in PHP
#1

Currently I have a table displaying all of the agents and a count of their leads status shown in the same row. Now these agents can be Active or Inactive, but both are shown in my table. This active/inactive status is shown in my users table under the status column as either Y or N. Now this is the code I'm using to get my data:

Model Class:


Code:
function get_agentsreport(){       
$this->db->select("l.lead_status,cu.display_name,cu.status,count(*) as leadnum,l.enquiry_date");       
$this->db->from($this->table_name." as l");         
$this->db->join("crm_clients_users cu","cu.id= l.lead_agent","left");          $this->db->join("crm_clients_users cu2","cu2.id= l.external_agent","left");          $this->db->group_by("l.lead_status,cu.id,cu2.id");       
$query = $this->db->get();      }


View Class:


Code:
<?php
    $ls_arr = array(1=>'Open',8=>'Hot',2=>'Closed',3=>'Transacted',4=>'Dead',9=>'Follow Up',11=>'Working');
    foreach($groupedleads as $grplead){
        $statuses[] = $status = $ls_arr[$grplead["lead_status"]];
        if($grplead["display_name"] == NULL || $grplead["display_name"] == '')
            $grplead["display_name"] = "Unknown";
        if(isset($grplead["display_name"]))
            $display_names[] = $display_name = $grplead["display_name"];
        $leaddata[$status][$display_name] = $grplead["leadnum"];
        if($grplead['status'] == "N"){
                    $inactive_status == true;
                }
    }

    if(count($display_names) > 0)
      $display_names = array_unique($display_names);
   
?>
<table>
          <?php
          if(is_array($display_names))
            foreach($display_names as $display_name){
          ?>
              <tr>
                  <?php
                    $total = 0;
                    $nonContact_total=0;
                    if ($inactive_status )
                      echo "<td style='background-color:#000'>".$display_name."</td>";
                    else
                      echo "<td>".$display_name."</td>";
                    foreach ($statuses as $status) {
                    ...
                    }
          <?php } ?>
</table>

Now I'm trying to differentiate the active and inactive users by a change in the style and as shown here I've tried if($grplead['status'] == "N"){$inactive_status == true;} but in my table it always goes to the else statement and doesn't compute the first if statement. I've also tried if($grplead['status'] == "Y"){$inactive_status == true;} but it gives the same output.

I've tried logging this status by print_r($grplead['status']); which gave the correct result like YYYYNY. So it is giving the correct status for each person, but for some reason it does not work in my if condition
Reply
#2

The bug is here :
PHP Code:
if($grplead['status'] == "N"){
    $inactive_status == true;


$inactive_status is never initialized. There should only be one equal sign, and it should be set to false if status is not equal to N :
PHP Code:
if($grplead['status'] == "N") {
    $inactive_status true;
} else {
    $inactive_status false;


…and could be simplified like this :
PHP Code:
$inactive_status = ($grplead['status'] == "N"); 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB