我有一个对结果进行分组的SQL查询。 print_r显示了我想要的结果。现在我想在表格组中显示这些结果,即表格1列出了该表格的所有席位,表格二等。
我已经尝试过各种各样的事情来完成这件事但是没有用......这是代码。我可以轻松地显示记录 - 但希望按组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
答案 0 :(得分: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
在此示例中,创建一个数组$表,其中包含您的席位,按','。
排序它的帮助?
答案 1 :(得分: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 />";
}