18 Mart 2010, PERŞEMBE
Nasıl oluşturmak için .PHP ile dosya json?
CREATE TABLE Posts
{
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(200),
url VARCHAR(200)
}
json.php kod
<?php
$sql=mysql_query("select * from Posts limit 20");
echo '{"posts": [';
while($row=mysql_fetch_array($sql))
{
$title=$row['title'];
$url=$row['url'];
echo '
{
"title":"'.$title.'",
"url":"'.$url.'"
},';
}
echo ']}';
?>
results.json
dosyası oluşturmak için var.
CEVAP
18 Mart 2010, PERŞEMBE
İşte örnek bir kod:
<?php
$sql=mysql_query("select * from Posts limit 20");
$response = array();
$posts = array();
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$title=$row['title'];
$url=$row['url'];
$posts[] = array('title'=> $title, 'url'=> $url);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?>
Bunu Paylaş:
Nasıl bir dosya oluşturmak ve Java ile...
Nasıl Eclipse MUAYENE bir dosya oluştu...
Nasıl Windows komut satırında boş bir ...
Nasıl Android bir dosya oluşturmak içi...
Nasıl json oluşturmak için döngü için ...