Why is it? I tried the same query in the console and it returned multiple rows. Here’s the query:
$this->wpdb->get_row("SELECT * FROM ".$this->wpdb->users." WHERE status = 'active'", ARRAY_A);
It keeps returning the same single row when there are several active users. Am I missing something?
Indeed, use
get_row()
only when you expect to get one result, else you can useget_results()
There are three ways to pull data from the database.
1.
$wpdb->get_var
:use this to get a single value from the database table. Like if you want to count the total number of comments. You can do it in following way:2.
$wpdb->get_row
: To retrieve an entire table row you can use this.Example:
OR
By using the
ARRAY_A
parameter in get_row your post data is returned as an associative array. Alternatively, you could use theARRAY_N
parameter to return your post data in a numerically indexed array.3.
$wpdb->get_results
:StandardSELECT
queries should use the get_results function for retrieving multiple rows of data from the database.and you need the last one, as you can expect.
row_offset
(integer) The desired row (0 being the first). Defaults to 0.
va http://codex.wordpress.org/Class_Reference/wpdb
my solution is simple..
Use: