Skip to content

Instantly share code, notes, and snippets.

@hiro-matsuno
Created August 19, 2014 01:00
Show Gist options
  • Save hiro-matsuno/f794b78c84b4fd5c7192 to your computer and use it in GitHub Desktop.
Save hiro-matsuno/f794b78c84b4fd5c7192 to your computer and use it in GitHub Desktop.
PHPでJSONを作るための方法(データが決まっている場合)
//取得関数の初期化
$blogReadList = array();
//リザルトからJSON用変数への投入
if(!empty($result)){
while($row = mysql_fetch_array($result)){
$blogReadList['blogId'] = isset($row['blogId'])? $row['blogId']:"";
$blogReadList['blogDate'] = isset($row['blogDate'])? $row['blogDate']:"";
$blogReadList['blogTitle'] = isset($row['blogTitle'])? $row['blogTitle']:"";
$blogReadList['blogContent'] = isset($row['blogContent'])? $row['blogContent']:"";
$blogReadList['id'] = isset($row['id'])? $row['id']:"";
}
}
//JSON配列化
echo json_encode($blogReadList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment