ユーザーがアイテムを持っているかどうか (はいまたはいいえ)、ユーザーからのアイテムの説明、および 3 番目に全員からの説明の json 配列を示す json 出力を取得しようとしています。
私はこのコードでこれを達成しようとしています:
//prepare variables for getting other user notes
$review = array();
if (numberOfNotes > 0) {
for ($i=0; $i < $numberOfNotes ; $i++) {
//get row
$row = $resultNotes->fetch_assoc();
$writerID = $row['userID'];
$tastedBeerID = $row['beerID'];
$noteID = $row['noteID'];
$note = $row['note'];
$note = urldecode($note);
//get username from id
//get user name
@ $db = new myConnectDB();
$query = "SELECT userName FROM user WHERE userID = $writerID";
$result2 = $db->query($query);
$row2 = $result2->fetch_assoc();
$writerName = $row2['userName'];
//trim note to 200 characters
$note = limitwords($note,150,$trail='...');
$count = $i + 1;
//add to array of notes
$review[] = array('userName' => "$writerName" ,'review' => "$note" );
}
}
//print yes if user has beer
$d = array('status' => 'yes' ,'userNote' => $alreadyWrittenNote , 'allNotes' => $review );
}
$jsonCode = json_encode($d);
$d で最初の 2 つの項目が正しく機能していますが、'allNotes' で $review[] の配列を出力できません。
私はこれを出力として取得しています:
{"status":"yes","userNote":" Pours a dark brown with a two finger head, with initial smell of a really smooth bourbon. \n\nFirst impression, a really smooth bourbon with roasted hints. While drinking this I can not express how smooth it is, but it ends with a nice slight tingling sensation on the tongue which really rounds the beer off nicely. There are also very slight hints of chocolate and a medium bitterness. ","allNotes":[]}
allNotes:[] にデータがないのはなぜですか?