1
我有一段代碼,我想通過我的json數組,不包含在數據庫$行中。所以我試圖設置一個自定義變量,並沒有奏效。有沒有辦法做到這一點,以便下面的內容通過數組發送?不通過json數組傳遞數據庫中的變量
這裏是我試過
PHP
if ($photo_numff == 1) {
$streamitem_uploadimage_count =" Uploaded new image";
} else if($photo_numff > 1) {
$streamitem_uploadimage_count =" Uploaded ".$photo_numff." new images";
} else {
}
JSON陣列
$rowcount = mysqli_num_rows($result);
$json = array(
'posts' => array(),
'count' => $rowcount
);
while ($row = mysqli_fetch_array($result)) {
$posts[] = array(
//Post information and ids
'streamitem_id' => $row['streamitem_id'], // post id
'streamitem_uploadimage_count' => $streamitem_uploadimage_count,
);
$rowcount++;
}
$json['posts'] = $posts;
echo json_encode($json);
然後我就可以通過我的ajax藉此"+response['streamitem_uploadimage_count']+"
我也曾嘗試array_push($json['posts'], array('streamitem_uploadimage_count' => $streamitem_uploadimage_count,));
但不會由$ JSON數組也加入內
'streamitem_uploadimage_count' => $streamitem_uploadimage_count
工作
你可以將任何你想要的東西推到數組上,然後編碼你的JSON。 –
所以我需要'array_push()'來做到這一點? – Gateway
是的,你會使用'array_push()' –