0

我有一个对结果进行分组的 sql 查询。print_r 显示了我想要的结果。现在我想在表组中显示这些结果,即表一,其中包含该表的所有座位的列表,表二等。

我已经尝试了各种方法来完成这项工作,但无济于事......这是代码。我可以轻松地显示记录 - 但想按组显示它们 arghhh

$seatings = $wpdb->get_results("SELECT 
                               bb_cl_seating.table,  
                               bb_cl_seating.seat, 
                               bb_cl_seating.seat_id,  
                               bb_events_attendee.fname,  
                               bb_events_attendee.lname, 
                               bb_events_attendee.email
                          FROM bb_cl_seating
                          LEFT JOIN bb_events_attendee 
                          ON bb_cl_seating.id = bb_events_attendee.id
                          WHERE bb_cl_seating.event_id = '1' ");

foreach ($seatings as $seating) {


    } // Ends foreach
4

2 回答 2

0
$seatings = $wpdb->get_results("SELECT 
                               bb_cl_seating.table,  
                               bb_cl_seating.seat, 
                               bb_cl_seating.seat_id,  
                               bb_events_attendee.fname,  
                               bb_events_attendee.lname, 
                               bb_events_attendee.email
                          FROM bb_cl_seating
                          LEFT JOIN bb_events_attendee 
                          ON bb_cl_seating.id = bb_events_attendee.id
                          WHERE bb_cl_seating.event_id = '1' ");

foreach ($seatings as $seating => $group) {
    //$data[table] = seat,seat2,seat3...
    $data[$group[1]] = $data[$group[1]].','.$group[2];
    } // Ends foreach

在此示例中,创建一个数组 $data,其中您的座位按“,”排序。

它的帮助?

于 2013-09-24T19:28:21.820 回答
0

这成功了 - 希望它可以帮助其他人:-)

$seatings = $wpdb->get_results("SELECT bb_cl_seating.table, bb_cl_seating.seat, bb_cl_seating.seat_id, bb_events_attendee.fname, bb_events_attendee.lname, bb_events_attendee.email
FROM bb_cl_seating
LEFT JOIN bb_events_attendee ON bb_cl_seating.id = bb_events_attendee.id
WHERE bb_cl_seating.event_id = '1' 
ORDER BY bb_cl_seating.table, bb_cl_seating.seat
");



$table_title = '';
foreach($seatings as $result => $col) {


     if($table_title !== $col->table) {
        $table_title = $col->table;
        echo "<strong>$table_title</strong>";
        echo "<br />";
    }
于 2013-09-24T22:56:47.473 回答