views:

35

answers:

1

Hello I currently have this PHP Script

        <?php if($purchase_dates != FALSE){?>
                        <?php foreach($purchase_dates as $id=>$outer_value) { ?>
                        <!-- Output the date here -->
                          <!-- Start Purchase table -->
                          <?
                          $date = strtotime($outer_value['date_purchased']);
                          $data = date('F jS Y', $date);
                          ?>

                          <h3></h3>
                          <!-- Start inner loop -->
                          <?php foreach($purchases as $id=>$inner_value) { ?>
                           <?php if($inner_value['date_purchased'] == $outer_value['date_purchased']) { ?>
                                <div class="row"> 
                                    <ul> 
                                        <li class="id"><a href="/search/cv/<?=$inner_value['code'];?>"><?=$inner_value['code'];?></a></li> 
                                        <li class="name"><a href="/search/cv/<?=$inner_value['code'];?>"><?=$inner_value['firstname'];?> <?=$inner_value['surname'];?></a></li>
                                        <li class="download"><a href="">Download PDF</a></li>
                                        <div class="disp"> 
                                            <li class="location"><?=$inner_value['city'];?></li> 
                                            <li class="status"><?=$job_status[$inner_value['job_status']];?></li> 
                                            <li class="education"><?=$education_types[$inner_value['education_level']]['nice_name'];?></li>
                                            <li class="role">
                                                <?php
                                                $out = array();
                                                if($inner_value['is_contract'] == 'Y') $out[]="Contract";
                                                if($inner_value['is_permanent'] == 'Y') $out[]="Permanent";
                                                if($inner_value['is_temporary'] == 'Y') $out[]="Temporary";
                                                echo implode(", ",$out);
                                                ?>
                                            </li> 

                            <li class="salary"><?=$salaries[$inner_value['expected_salary_level']]['nice_name'];?></li> 
                                        </div>
                                    </ul> 
                                </div>
                           <?php  } ?>
                          <?php  } ?>
                          <!-- End inner loop -->
                        <?php } ?>
                        <?php }?>
                        <!-- End Outer Tree Loop -->

This generates something that looks like this,

22nd July
Purchase1

22nd July
Purchase 2

18th July
Purchase 3

18th July
Purchase 4

My question is, I want to group all the purchases that are on the same under that date and also if that date is todays date I want to replace '23rd July' with 'Todays Purchases'

I am already using groupby in my SQL

A: 

The easiest way to group by a date is to add an extra dimension to your arrays, so all entries that belong to the same date are in the same subarray. Then you just need to loop twice:

foreach($data as $purchase_date => $purchases){
    // Print date
    foreach($purchases as $id=>$inner_value){
        // Print purchase
    }
}

You appear to be using Unix timestamps for dates, so you can simply use date() to strip hours, minutes and seconds:

if( date('Y-m-d')==date('Y-m-d', $purcharse_date) ){
    // Today
}
Álvaro G. Vicario
Sorry I am not following that answer could you apply it to my code please?
sea_1987