A
A
Alex99342021-01-28 12:04:06
WordPress
Alex9934, 2021-01-28 12:04:06

After $wpdb->get_results there is a filled array, but you can't access its elements?

$result = $wpdb->get_results("SELECT *  FROM table WHERE qwe='$qwe'" ,ARRAY_N 
                                                 );
print_r($result);
//выводит нужный результат
// Array ( [0] => Array ( [0] => 13 [1] => поле1 [2] => поле2 [3] => поле3 ) )

But when I try to access an array element, it returns an empty value.

foreach($result AS $key=>$value) {
  echo $key . " -> " . $value;
}
//выдает
//0 -> Array

Or like this
echo ($result[2]);
//пустой результат


That is, the array is filled, this can be seen through print_r, but it is not possible to access the array element.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Klepko, 2021-01-29
@gaz12

Instead of ARRAY_N use ARRAY_A.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question