$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How does $wpdb->get_var work with offset?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How does $wpdb->get_var work with offset?

matteradmin8PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

You 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" ); ?> 

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far