Display by month

Display by month - The data I am pulling from the database is creating new column headers for each month. I am not sure where i did this so I was looking for someone to look at my code and see where i should remove it.
index.php
j8547Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
Your problem is within this block of code:
<?php foreach ($collection as $date => $records): // Loop through the new array to output the records ?>
    <table Width= "100%" border="1" cellspacing="0" cellpadding="1">
		 <?php doHeaders($records[0]);

Open in new window


You are printing the headers inside the loop (which iterated once for each date). If you only want the headers printed once, you'll have to print them outside of that loop.
0
Jan LouwerensSoftware EngineerCommented:
Or, another option, is to only print them if they haven't been printed yet.

<?php
   $headersPrinted = false;
   
   foreach ($collection as $date => $records): // Loop through the new array to output the records
?>
    <table Width= "100%" border="1" cellspacing="0" cellpadding="1">
<?php
   if (!$headersPrinted)
   {
      doHeaders($records[0]);
      $headersPrinted = true;
   }
   ...

Open in new window

0
j8547Author Commented:
I got it working with your code but the table borders are doubled where it doesn't print the header....

Is there a way I can change the 'For each' to remove the as $date...
0
Jan LouwerensSoftware EngineerCommented:
Oh right. That table tag should also be within the if condition:

<?php
   $headersPrinted = false;
   
   foreach ($collection as $date => $records): // Loop through the new array to output the records
   
   if (!$headersPrinted)
   {
?>
    <table Width= "100%" border="1" cellspacing="0" cellpadding="1">
<?php
      doHeaders($records[0]);
      $headersPrinted = true;
   }
   ...

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
j8547Author Commented:
That doesn't work neither.. It prints the first row in a column and then the rest outside the table. all the other values
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.