W
W
webdeveloper482015-11-13 15:54:59
PHP
webdeveloper48, 2015-11-13 15:54:59

Am I processing the array incorrectly?

Here's what I get when I query dpaste.com/2ZHXNXN
Here's the code dpaste.com/02SY6C0
On the second foreach pass, $val is empty. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
murrometz, 2015-11-13
@webdeveloper48

foreach ($ar as $val) { is an extra loop.
You get an array of $row. Here on it also it is necessary to iterate.
$i++; move it to the outer loop while
$j++ - to the loop through the array.

M
Mikhail Smykov, 2015-11-13
@Chronosms

It's better to immediately use the associative mysqli_fetch_assoc
And in general: I don't like your while ($db = mysqli_fetch_assoc( ... ))...

E
Evgeniy Odinets, 2015-11-13
@evgeniy2194

PS: You can't send headers after something has been rendered on the page.

I
Ilya Beloborodov, 2015-11-13
@kowap

Warning: Invalid argument supplied for foreach()
This error usually occurs if there is nothing to "foreach". Check array for non-emptiness before using foreach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question