i have this code
$Query = mysql_query("Select*from mbulan");
while ($row = mysql_fetch_array($Query, MYSQL_ASSOC)) {
$items = array($row['id']=>$row['bulan']);
foreach ($items as $key=>$value) {
echo json_encode(array("$value"));}
}
and the output something like this :
["January"]["Fabruary"]["Maret"]["April"]["Mei"]["Juni"]
but i wan change the output like :
["January","February","Maret","April","Mei","Juni"]
what should i do for the code and where is the code must be change it ?
You can use the following code ..
$Query = mysql_query("SELECT * FROM mbulan");
$item = array();
while ($row = mysql_fetch_array($Query, MYSQL_ASSOC)) {
$items[] = $row['bulan'];
}
echo json_encode($items);
Feel free to ask any questions.
json_encode turns an entire array into one json string, so just get all of you months into one array and output it
$Query = mysql_query("Select bulan from mbulan");
while ($row = mysql_fetch_array($Query, MYSQL_ASSOC)) {
$bulan[] = $row['bulan'];
}
echo json_encode($bulan)
You should also use pdo for better results, and for more long-term support. http://www.php.net/manual/en/book.pdo.php