$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'); ?>php - Any possible way to make $wpdb->get_results() return anything else than array?|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)

php - Any possible way to make $wpdb->get_results() return anything else than array?

matteradmin11PV0评论

So I'm using $wpdb->get_results() to query my database and then make AJAX call from JS file. The problem is that I need to get the value itself, like a string, instead of array, but as much as I know, get_results return only array. Is there any way around this to get string value from database? Or should I use something else than get_results()?

So I'm using $wpdb->get_results() to query my database and then make AJAX call from JS file. The problem is that I need to get the value itself, like a string, instead of array, but as much as I know, get_results return only array. Is there any way around this to get string value from database? Or should I use something else than get_results()?

Share Improve this question asked Nov 13, 2018 at 17:27 LimpulsLimpuls 3071 gold badge3 silver badges16 bronze badges 2
  • Why not use that array and get the string from it? – kero Commented Nov 13, 2018 at 17:32
  • I converted it to JSON but still don't know how to access the string in the loop. I have an array of json objects here. Any hints? – Limpuls Commented Nov 13, 2018 at 17:55
Add a comment  | 

1 Answer 1

Reset to default 1

$wpdb->get_results() only returns arrays( associative or numeric) or an object. It does not return a string value.

If you want a string value, you need to use $wpdb->get_var() instead

Post a comment

comment list (0)

  1. No comments so far