java - Format array where data take from table database -


i have code

$query = mysql_query("select*from mbulan"); while ($row = mysql_fetch_array($query, mysql_assoc)) { $items = array($row['id']=>$row['bulan']); foreach ($items $key=>$value) {         echo json_encode(array("$value"));} } 

and output :

["january"]["fabruary"]["maret"]["april"]["mei"]["juni"] 

but wan change output :

["january","february","maret","april","mei","juni"] 

what should code , code must change ?

json_encode turns entire array 1 json string, of months 1 array , output it

$query = mysql_query("select bulan mbulan"); while ($row = mysql_fetch_array($query, mysql_assoc)) {      $bulan[] = $row['bulan']; }  echo json_encode($bulan) 

you should use pdo better results, , more long-term support. http://www.php.net/manual/en/book.pdo.php


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -