填充php表不同的字段和标题

时间:2015-09-28 11:36:15

标签: php html wordpress

需要一些帮助,因为我有非常基本的代码知识,不确定我理解我需要什么。

我从wordpress插件支持中获得了两组代码,他们说这些代码可以帮助我做我需要做的事情

我的目标是根据名为与会者表单的字段显示不同数据和标题的表格(每个与会者表单具有不同的字段)。

他们给了我两个代码。

第一个显示一个表,但我不得不手动输入每个表头而且它不是动态的

function my_attendee_form (){
$people = array();
$EM_Bookings = $EM_Event->get_bookings();
if( count($EM_Bookings->bookings) > 0 ) 
{
    echo "\n";
    ?>
    <table class="event-attendees">
            <tr class="">
                    <th class="attendee-name">Name</th>
                    <th class="attendee-country">Golf Link</th>
                    <th class="attendee-discipline">Handicap</th>
                    <th class="attendee-status">Home Club</th>
            </tr>
    <?php
    $guest_bookings                 = get_option('dbem_bookings_registration_disable');
    $guest_booking_user     = get_option('dbem_bookings_registration_user');
    $counter = 0;
    foreach( $EM_Bookings as $EM_Booking){
                $attendees_list = "";
              $attendees = $EM_Booking->booking_meta['attendees'];
                     if ( !empty($attendees) ) {

                            $attendees_list = "";
                            foreach($attendees as $key => $value) {
                              foreach($value as $key_attendee => $value_attendee) {
                              $attendees_list .= "<tr>";
                              $attendees_list .= "<td>".$value_attendee["attendee_name"]."</td>";
                              $attendees_list .= "<td>".$value_attendee["golflink"]."</td>";
                              $attendees_list .= "<td>".$value_attendee["handicap"]."</td>";
                                $attendees_list .= "<td>".$value_attendee["home_club"]."</td>";
                              $attendees_list .= "</tr>";
                                  }
                            }   
                    }
echo $attendees_list;
    }
    echo "\n";
    ?>
    </table>
    <?php
 }
if( count($EM_Bookings->bookings) == 0 ) 
    {
    echo '<p>No one registered yet... Will you be the first ?</p>'};        
    }


add_action('em_bookings_event_footer', 'my_attendee_form');

这稍微破了,表格有效。

第二位代码将一列添加到现有表中,并根据表单字段填充它。

function my_em_bookings_table_cols_template_attendee2($template,      $EM_Bookings_Table){
$template['attendee_name'] = 'Attendee Name';
return $template;
}
add_action('em_bookings_table_cols_template',    'my_em_bookings_table_cols_template_attendee2',10,2);

function my_em_custom_booking_form_cols_attendee_list($val, $col, $EM_Booking, $EM_Bookings_Table, $csv){

if( $col == 'attendee_name' ){

    $EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
    $attendee_datas = EM_Attendees_Form::get_booking_attendees($EM_Booking);
    $attendee_list = "";
    foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){

        //Display ticket info
        if( !empty($attendee_datas[$EM_Ticket_Booking->ticket_id]) ){
            $val .= "<ul>";
            $val .= "<li> <strong>Ticket name: ".$EM_Ticket_Booking->get_ticket()->ticket_name."</strong></li>";
            foreach( $attendee_datas[$EM_Ticket_Booking->ticket_id] as $attendee_title => $attendee_data ){
                $val .= "<li>".$attendee_title."</li>";
                $val .= "<li><ul>";
                foreach( $attendee_data as $field_label => $field_value){
                    $val .=  "<li>". $field_label .': '.$field_value."</li>";
                }
                $val .= "</ul></li>";
            }
            $val .= "<ul>";
        }


    }

}

return $val;
}  
         add_filter('em_bookings_table_rows_col','my_em_custom_booking_form_cols_attendee_list', 10, 5);

我如何将这两者结合起来,以便我可以像第一个代码一样生成一个新表,但是像第二个代码那样填充它?我只是不知道到底在哪里。

任何建议/想法都会很棒。

由于 特洛伊

0 个答案:

没有答案