Database Query to WordPress Database Returns a Count, not Rows

I have the follow query I’m making to a MySQL database, for a WordPress website:

global $wpdb; 

/*get time slots*/
$query = "
    SELECT DISTINCT routes.route_date, time_slots.name, time_slots.openings, time_slots.appointments
    FROM routes
    INNER JOIN time_slots ON routes.route_id = time_slots.route_id
    WHERE route_date
    BETWEEN 20140110
    AND 20140227 
    ORDER BY route_date, name
    "; 
$time_slots = $wpdb->query($query);

However the value of $time_slots is 245. Just a number. I don’t know why. When I make the query in phpmyadmin, using the exact query, I get the expected results.

Read More

What am I doing wrong here and how can I get the array I’m expecting.

Related posts

Leave a Reply

3 comments

  1. Well you are right

      <?php $result = $wpdb->query('query'); ?> 
    

    $result will contain the number of rows affected, not the results

    do this instead:

              $result =  $wpdb->get_results($query);