I have a query that pulls values from multiple tables. I want to order them by shows_date ASC only I cant seem to get it to ouput any data, Can anybody see a problem with my syntax?
$artists = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_SHOWS . " AS s, ORDER BY s.show_date ");
var_dump($artists);
foreach($artists as $artist_group)
{
$shows = $wpdb->get_results("SELECT *
FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s
LEFT JOIN " . GIGPRESS_TOURS . " AS t
ON s.show_tour_id = t.tour_id
WHERE " . $date_condition . "
AND show_status != 'deleted' AND s.show_artist_id = " . $artist_group->artist_id . "
AND s.show_artist_id = a.artist_id AND s.show_venue_id = v.venue_id " . $further_where . "
ORDER BY s.show_date " . $sort . ",s.show_expire " . $sort . ",s.show_time ". $sort . $limit);
}
DUMP RETURNS
array(72) { [0]=> object(stdClass)#260 (25) { [“artist_id”]=> string(1) “1” [“artist_name”]=> string(14) “Damien Dempsey” [“artist_order”]=> string(1) “0” [“show_id”]=> string(1) “1” [“show_artist_id”]=> string(1) “1” [“show_venue_id”]=> string(1) “1” [“show_tour_id”]=> string(1) “0” [“show_date”]=> string(10) “2012-01-29” [“show_multi”]=> string(1) “0” [“show_time”]=> string(8) “20:30:00” [“show_expire”]=> string(10) “2012-01-29” [“show_price”]=> string(7) “£10.00” [“show_tix_url”]=> string(0) “” [“show_tix_phone”]=> string(0) “” [“show_ages”]=> string(8) “All Ages” [“show_notes”]=> string(0) “” [“show_related”]=> string(1) “0” [“show_status”]=> string(7) “deleted” [“show_tour_restore”]=> string(1) “0” [“show_address”]=> NULL [“show_locale”]=> NULL [“show_country”]=> NULL [“show_venue”]=> NULL [“show_venue_url”]=> NULL [“show_venue_phone”]=> NULL } [1]=> object(stdClass)#259 (25) { [“artist_id”]=> string(1) “2” [“artist_name”]=> string(10) “Gary Dunne” [“artist_order”]=> string(1) “0” [“show_id”]=> string(1) “1” [“show_artist_id”]=> string(1) “1” [“show_venue_id”]=> string(1) “1” [“show_tour_id”]=> string(1) “0” [“show_date”]=> string(10) “2012-01-29” [“show_multi”]=> string(1) “0” [“show_time”]=> string(8) “20:30:00” [“show_expire”]=> string(10) “2012-01-29” [“show_price”]=> string(7) “£10.00” [“show_tix_url”]=> string(0) “” [“show_tix_phone”]=> string(0) “” [“show_ages”]=> string(8) “All Ages” [“show_notes”]=> string(0) “” [“show_related”]=> string(1) “0” [“show_status”]=> string(7) “deleted” [“show_tour_restore”]=> string(1) “0” [“show_address”]=> NULL [“show_locale”]=> NULL [“show_country”]=> NULL [“show_venue”]=> NULL [“show_venue_url”]=> NULL [“show_venue_phone”]=> NULL } [2]=> object(stdClass)#261 (25) { [“artist_id”]=> string(1) “3” [“artist_name”]=> string(19) “London Irish Centre” [“artist_order”]=> string(1) “0” [“show_id”]=> string(1) “1” [“show_artist_id”]=> string(1) “1” [“show_venue_id”]=> string(1) “1” [“show_tour_id”]=> string(1) “0” [“show_date”]=> string(10) “2012-01-29” [“show_multi”]=> string(1) “0” [“show_time”]=> string(8) “20:30:00” [“show_expire”]=> string(10) “2012-01-29” [“show_price”]=> string(7) “£10.00” [“show_tix_url”]=> string(0) “” [“show_tix_phone”]=> string(0) “” [“show_ages”]=> string(8) “All Ages”
Ive tried the following
foreach($artists as $artist_group) {
$shows = $wpdb->get_results("SELECT * FROM " . GIGPRESS_ARTISTS . " AS a, " . GIGPRESS_VENUES . " as v, " . GIGPRESS_SHOWS ." AS s LEFT JOIN " . GIGPRESS_TOURS . " AS t ON s.show_tour_id = t.tour_id WHERE " . $date_condition . " AND show_status != 'deleted' ORDER BY s.show_date ASC " . $limit);
Which works in regards to the ordering, but it outputs each value about 100 times or something stupid..
the comma after AS s, is extraneous
additionally you seem to be missing a WHERE clause or a JOIN ON statement.
this query would produce a cross-join with (all gigs) x (all bands) so that in your foreach you will process each band once for every gig in the system, instead of once for each band/show.