1

I am so close to figuring this out, this is using Wordpress and Gravity Forms Plugin:

<?php
        $form_id = '1'; // The registration form's ID
        $entries =  GFAPI::get_entries( $form_id ); // Get all entries

        $html = "<table class='ent'>"; // Create an HTML table          
        $html .= "<tr><th>Name</th><th>Organization</th><th>Event</th><th>Date</th><th>Number Attending</th></tr>";

        $list = array(); // Array to store the original fields  
        $used = array(); // Array to stored the "used" fields

        // Loop through array of entries,each element 
        foreach($entries as $entry){

            // Get datepart from datetime of event and today's date
            $date = date_format(new DateTime($entry['8']), 'Y-m-d');
            $today = date("Y-m-d");

            // Compare event's date with current date
            if ( $date >= $today ) {

                $list[] = $entry;

                if (!empty($used[$entry['6']])) // If used[event name] not null then sum associated numattend
                {
                    $used[$entry['6']] += $entry['5'];
                }   
                else // return associated numattend
                {
                    $used[$entry['6']] = $entry['5'];
                }
            } 
        }   
        unset($entry);

       foreach ($used as $key => $value) {
          foreach ($list as $key1 => $value1) {
              $html .= "<tr><td>" . $value1['1'] . " " . $value1['2'] . "</td><td>" . $value1['93']  . "</td><td>" . $value1['6'] . "</td><td>" . $value1['8']  . "</td><td>" . $value1['5'] . "</td></tr>";
          }
          $html .= "<tr class='ent_sum_rw'><td>" . "&nbsp;" . "</td><td>" . "&nbsp;" . "</td><td>" . "&nbsp;" . "</td><td class='ent_sum'>" . "Total Attending:" . "</td><td>" . $value . "</td></tr>";
     }
     unset($value);

     $html .= "</table>";
     return $html;
?>

Result: Result1

I want the loop to end the entry list on the corresponding "Event Name", Like "Test Event 22" should not show up on the top entry list.

2
  • Could you give us an example of what foreach($entries as $entry){ print_r($entry); } gives? i think you want every event grouped, but i want to see the result first. Commented Mar 31, 2016 at 18:57
  • pastebin.com/JC1aAG7L Commented Mar 31, 2016 at 19:08

1 Answer 1

2

The trick is to populate an Array that meets your demands and after that convert it to html. I haven't tested the code, but it should be clear how it works.

$aEventList = Array();
foreach($entries as $entry){
    if (!isset($aEventList[$entry['7']])){ //7 is id of event
        //if this event is not made, create it and add name and the date, enter the right numeral
        $aEventList[$entry['7']]['name'] = $entry['6'];
        $aEventList[$entry['7']]['date'] = $entry['90'];
        $aEventList[$entry['7']]['users'] = Array();
    } 
    $aEventList[$entry['7']]['users'][] = Array('name' => $entry['1'] . ' '. $entry['2'],
                                                'org' => $entry['93'],
                                                'num' => $entry['5']);
}
//now you've populated every event and you can loop through it on your desired way:
foreach ($aEventList as $iEvent => $aEvent){
    echo $aEvent['name']; //event name
    echo $aEvent['date']; // event date
    foreach ($aEvent['users'] as $aEventUser){
        echo $aEventUser['name']; // user name
        echo $aEventUser['org']; // user organisation
        echo $aEventUser['num']; // num attendees
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yes this does the trick! Thanks I tried something like this earlier, but it would give me errors when I would reference the ['key'] obviously was referencing them wrong.
Thank you so much Garytje, you save me a lot of time! This worked like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.