A
A
Ayk722015-02-26 17:02:47
PHP
Ayk72, 2015-02-26 17:02:47

How to make json in a loop?

Hello!
How to make json response in php mysql loop.

$rw = $db->query( "SELECT id,name FROM dle_category WHERE parentid='{$_POST['id']}' ORDER by id ASC" );
while ($row = $db->get_row($rw)) {

$row['name'] = iconv('windows-1251', 'UTF-8', $row['name']);

$v = array($row['id'] => $row['name']);

}
echo json_encode($v);

It works great, BUT how to make it so that there is not 1 answer from the loop, but all?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
XpeH Petrovich, 2015-02-26
@Ayk72

if I have not completely forgotten how to write on it, then
well, in the sense it should be written instead
$v = array($row['id'] => $row['name']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question