1

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.

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

3
  • Please stop creating [database-query]. It is entirely unnecessary. We already have tags to cover the concept of database queries. Your question already has those tags. Commented Jan 11, 2014 at 8:09
  • 1
    Didn't realize it was that big of a deal. Maybe you can send me a list of tags you've approved. Commented Jan 11, 2014 at 8:10
  • Duplicate tags are a big deal! Tags are here to help categorize questions. If people pick the "wrong" one of a set of tags that are effectively the same, they risk not having their question found. Commented Jan 11, 2014 at 23:33

3 Answers 3

1

use for all record

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

use for fetch row

$time_slots = $wpdb->get_var($query);
Sign up to request clarification or add additional context in comments.

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

1 Comment

$wpdb is the global variable to access the Wordpress database. It has nothing to do with the number of affected rows.
-1

function wpse_footer_db_queries(){ echo ''.PHP_EOL; } add_action('wp_footer', 'wpse_footer_db_queries');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.