In WordPress documentation, it says:
()
SELECT a Variable The get_var function returns a single variable from the database. Though only one variable is returned, the entire result of the query is cached for later use. Returns NULL if no result is found.
get_var( 'query', column_offset, row_offset ); ?>query (string) The query you wish to run. Setting this parameter to null will return the specified variable from the cached results of the previous query. column_offset (integer) The desired column (0 being the first). Defaults to 0. row_offset (integer) The desired row (0 being the first). Defaults to 0.
My query is, can you please explain this line:
Setting this parameter to null will return the specified variable from the cached results of the previous query.
Which variable? If i code:
<?php $wpdb->get_var( null, column_offset, row_offset ); ?>
Which variables value is it talking about?
Thanks.
In WordPress documentation, it says:
(https://codex.wordpress/Class_Reference/wpdb)
SELECT a Variable The get_var function returns a single variable from the database. Though only one variable is returned, the entire result of the query is cached for later use. Returns NULL if no result is found.
get_var( 'query', column_offset, row_offset ); ?>query (string) The query you wish to run. Setting this parameter to null will return the specified variable from the cached results of the previous query. column_offset (integer) The desired column (0 being the first). Defaults to 0. row_offset (integer) The desired row (0 being the first). Defaults to 0.
My query is, can you please explain this line:
Setting this parameter to null will return the specified variable from the cached results of the previous query.
Which variable? If i code:
<?php $wpdb->get_var( null, column_offset, row_offset ); ?>
Which variables value is it talking about?
Thanks.
Share Improve this question edited Mar 16, 2019 at 21:41 Nabeel Khan asked Apr 4, 2016 at 22:21 Nabeel KhanNabeel Khan 4185 silver badges17 bronze badges 1- Please improve your question title. Summarize your specific problem. – fuxia ♦ Commented Apr 4, 2016 at 23:11
1 Answer
Reset to default 1You must specify values for column_offset and row_offset. For example:
<?php $wpdb->get_var( null, 5, 0 ); ?>
Will return "Hello World" (see attached image) But for that to work you had to have a previous query like this:
<?php $wpdb->get_var( "SELECT * FROM $wpdb->posts" ); ?>