$selected_offer = $_POST['selected_offer'];
$get_categories = $db->query("SELECT oc_id, oc_name FROM object_category WHERE oc_relate = '".$selected_offer."'");
$json = array();
while ($get_rows = mysql_fetch_array($get_categories, MYSQL_ASSOC)) {
$json[] = $get_rows;
}
echo json_encode($json);
return;
我从其他人那里获得了这段代码,由于我不熟悉 json,我在 stackoverflow 上问如何在 json 对其进行编码之前向 oc_name 属性添加一个函数,并且仍然返回与现在相同的 sstriketure,例如:
语言($get_行['oc_name'](
while ($get_rows = mysql_fetch_array($get_categories, MYSQL_ASSOC)) {
$get_rows['oc_name'] = language($get_rows['oc_name']);
$json[] = $get_rows;
}
您可以在将
行添加到$json
数组之前对上述字段应用函数
$json = array();
while ($get_rows = mysql_fetch_array($get_categories, MYSQL_ASSOC)) {
$get_rows['oc_name']=language($get_rows['oc_name']);
$json[] = $get_rows;
}