Jump to content

Conditional style for specific data in PHP


Go to solution Solved by requinix,

Recommended Posts

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:

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");
        $query = $this->db->get();

View Class:

    $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";
            $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);
            foreach($display_names as $display_name){ 
                    $total = 0;
                    if ($inactive_status )
                      echo "<td style='background-color:#000'>".$display_name."</td>";
                      echo "<td>".$display_name."</td>";
                    foreach ($statuses as $status) {
          <?php } ?>

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

Link to comment
Share on other sites

1 minute ago, requinix said:

You've got more problems in there than that, but

Don't do inline CSS. Give the TD a class name like "agent-status-Y" or "agent-status-N" and then create a CSS rule or two to give the TD appropriate styling accordingly.

More problems? But when I log `$grplead['status']` it gives me the correct output showing YYYYNY. And by css rule do you mean:

echo "<td class=" <?php echo $inactive_status == true?'agent-status-N':'agent-status-Y'">".$display_name."</td>"; ?

Link to comment
Share on other sites

  • Solution
9 hours ago, KSI said:

More problems?

Like how $inactive_status is never assigned a value. Or how it would be set to true if any of the agents are status=N.

And I don't understand why you have all this stuff dealing with $statuses and $display_names.


9 hours ago, KSI said:

But when I log `$grplead['status']` it gives me the correct output showing YYYYNY. And by css rule do you mean:

echo "<td class=" <?php echo $inactive_status == true?'agent-status-N':'agent-status-Y'">".$display_name."</td>"; ?

That's the general idea, though what you have there won't work (see what I said above).

You can throw class names onto whatever elements you want to represent whatever information you want, then add CSS rules to target things you care about.

Consider this:

$month = 10;
$year = 2021;

$daysinmonth = date("t", mktime(0, 0, 0, $month, 1, $year));

for ($day = 1; $day <= $daysinmonth; $day++) {
	$date = mktime(0, 0, 0, $month, $day, $year);

	list($monthname, $dayname, $weekday, $fulldate) = explode("/", date("F/l/N/F jS", $date));

	$isweekday = $weekday <= 5;


<span class="month-<?=$monthname?> day-<?=$dayname?> <?=$isweekday ? 'is-weekday' : 'is-weekend'?>">
	<?=$fulldate?> is a <?=$dayname?>





<span class="month-October day-Friday is-weekday">October 1st is a Friday</span>
<span class="month-October day-Saturday is-weekend">October 2nd is a Saturday</span>
<span class="month-October day-Sunday is-weekend">October 3rd is a Sunday</span>
<span class="month-October day-Monday is-weekday">October 4th is a Monday</span>

and then you can do things like

.day-Monday::after { content: "😢"; }
.day-Friday::after { content: "🎉"; }
.is-weekend { background-color: #ccc; }


Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.