dquv73115 2015-09-28 11:36
浏览 17

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

Need some help as I have very basic knowledge of code and not sure I understand what i need to.

I have been given two sets of codes from a wordpress plugin support that they say will help me do what I need to do

My goal is to have a table that display different data and headers based on a field called attendee form (each attendee form has different fields).

They have given me the two codes.

First one displays a table but I have had to manually enter each table header and it is not dynamic

function my_attendee_form (){
$people = array();
$EM_Bookings = $EM_Event->get_bookings();
if( count($EM_Bookings->bookings) > 0 ) 
{
    echo "
";
    ?>
    <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 "
";
    ?>
    </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');

This is slightly broken, the table works.

The second bit of code adds a column to an existing table and populates it based on the form fields.

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);

How would I combine these two so that I can generate a new table like the first code, but populate it like the second one? I just don't know what goes where.

Any suggestions/thoughts would be great.

Thanks Troy

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突