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

admin2025-06-06  2

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749182706a317052.html

最新回复(0)