Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

If statement help, alternating table row colors

I'm trying to get the days($day) that have no $activities not to show.
And the on the days that do have $activities to alternate the table row colors

See: http://www.holytrinitypmb.org/activities.php?eventsid=2

function activities()      {
            print("<style>tr:hover{background-color:#00ccff;}</style>");
                  
                  $events = getEvents(array("where"=>"eventsid=".$_GET["eventsid"]));
                  print("<h3 align=\"center\">".$events[0]["events"]."</h3>");
                  print("<table align=\"center\">");
                  $day = getDay();
                  foreach ($day as $keyday => $valday)      {
                  
                  print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
            
                  $activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));

                        foreach($activities as $key => $valact)      {
                         if($valday["dayid"]==$valact["dayid"]){

                         $time = date('g:i A' , strtotime($valact["time"]));

                     print("<tr><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
                         <td>".$valact["activities"]."</td>
                         <td>".$valact["venue"]."</td>
                         <td>".$valact["leader"]."</td>
                         <td>".$valact["contact"]."</td>
                         </tr>");

                         }
                        }
                  }
                  print("</table>");

            }
0
cybergary
Asked:
cybergary
  • 5
  • 5
1 Solution
 
Renante EnteraCommented:
Hi cybergary!

Let me revised your function...

function activities()     {
          print("<style>tr:hover{background-color:#00ccff;}</style>");
               
               $events = getEvents(array("where"=>"eventsid=".$_GET["eventsid"]));
               print("<h3 align=\"center\">".$events[0]["events"]."</h3>");
               print("<table align=\"center\">");
               $day = getDay();
               foreach ($day as $keyday => $valday)     {              
                         
               $activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));
               
               if(count($activities)) {
                 print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
               }

               $rowCount = 1; // initial row count...

                    foreach($activities as $key => $valact)     {
                     if($valday["dayid"]==$valact["dayid"]){

                     $time = date('g:i A' , strtotime($valact["time"]));

                    $bgColor = ($rowCount %2) ? 'F2F2F2' : 'CCCCCC';
                  print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
                     <td>".$valact["activities"]."</td>
                     <td>".$valact["venue"]."</td>
                     <td>".$valact["leader"]."</td>
                     <td>".$valact["contact"]."</td>
                     </tr>");

                     }
                    }
               }
               print("</table>");

          }

I hope that this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
 
cybergaryAuthor Commented:
Hi entrance2002

It does not work, it makes all the row background colors CCCCCC and all the days without events still show.

http://www.holytrinitypmb.org/activities.php?eventsid=2
0
 
cybergaryAuthor Commented:
I should say the days without activities still show.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Renante EnteraCommented:
Hi cybergary!

Sorry... I forgot something.  It should be this one :

function activities()     {
          print("<style>tr:hover{background-color:#00ccff;}</style>");
               
               $events = getEvents(array("where"=>"eventsid=".$_GET["eventsid"]));
               print("<h3 align=\"center\">".$events[0]["events"]."</h3>");
               print("<table align=\"center\">");
               $day = getDay();
               foreach ($day as $keyday => $valday)     {              
                         
               $activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));
               
               if(count($activities)) {
                 print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
               }

               $rowCount = 1; // initial row count...

                    foreach($activities as $key => $valact)     {
                     if($valday["dayid"]==$valact["dayid"]){

                     $time = date('g:i A' , strtotime($valact["time"]));

                    $bgColor = ($rowCount %2) ? 'F2F2F2' : 'CCCCCC';
                  print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
                     <td>".$valact["activities"]."</td>
                     <td>".$valact["venue"]."</td>
                     <td>".$valact["leader"]."</td>
                     <td>".$valact["contact"]."</td>
                     </tr>");

                     }
                     $rowCount++; // this line is missing...
                    }
               }
               print("</table>");

          }
0
 
cybergaryAuthor Commented:
Thanks that fixes alternating the row colors.

But the days that have no activities are still showing
0
 
Renante EnteraCommented:
Hmmm...  

Kindly add this code for debugging purposes:
-----------------------------------------------------------------------------------------
               ...
               print_r($activities); // i want to view the resulting array

               if(count($activities)) {
                 print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
               }
               ...
-----------------------------------------------------------------------------------------
0
 
cybergaryAuthor Commented:
0
 
Renante EnteraCommented:
OK!

Try this one :
-----------------------------------------------------------------------------------------------------------------------------
function activities()     {
          print("<style>tr:hover{background-color:#00ccff;}</style>");
               
               $events = getEvents(array("where"=>"eventsid=".$_GET["eventsid"]));
               print("<h3 align=\"center\">".$events[0]["events"]."</h3>");
               print("<table align=\"center\">");
               $day = getDay();
               foreach ($day as $keyday => $valday)     {              
                         
               $activities = getActivities(array("where"=>"eventsid=".$_GET["eventsid"],"order"=>"time"));

               // begin additional code
               $activityExist = false;

               foreach($activities as $xVal) {
                 if($valday["dayid"]==$xVal["dayid"])
                   $activityExist = true;
               }

               if($activityExist) {
                 print("<tr><th colspan=5>".$valday["day"]."</th></tr>\n\r");
               }
               // end additional code              

               $rowCount = 1; // initial row count...

                    foreach($activities as $key => $valact)     {
                     if($valday["dayid"]==$valact["dayid"]){

                     $time = date('g:i A' , strtotime($valact["time"]));

                    $bgColor = ($rowCount %2) ? 'F2F2F2' : 'CCCCCC';
                  print("<tr bgColor=$bgColor><td align=\"right\" style=\"padding-right:5px;\">".$time."</td>
                     <td>".$valact["activities"]."</td>
                     <td>".$valact["venue"]."</td>
                     <td>".$valact["leader"]."</td>
                     <td>".$valact["contact"]."</td>
                     </tr>");

                     }
                     $rowCount++; // this line is missing...
                    }
               }
               print("</table>");

          }
-----------------------------------------------------------------------------------------------------------------------------
This should resolved the problem.


Regards!
eNTRANCE2002 :-)
0
 
cybergaryAuthor Commented:
Thanks eNTRANCE2002 :-)
0
 
Renante EnteraCommented:
Hi cybergary!

Of course, you're always welcome.  I'm glad that I have helped you.  Hope to help you again...

Btw, thanks for the points and grade.


Best regards!
eNTRANCE2002 :-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now