我正在阅读使用AJAX通过另一个文档处理的文档请求。
在通过AJAX处理的文档中,我希望生成JSON数组,因为这是我传递两个变量,然后像这样传播它们的唯一方法
$('#country').append($('<option>').text(arr_values[1]).attr('value', arr_values[0])));现在我生成的代码如下
$results2 = mysql_query('SELECT full, short FROM `Countries` WHERE '.$cities);
$json = array();
while( $result2 = mysql_fetch_array($results2) ) {
$json[] = $result2['short'].','.$result2['full'];
}发布于 2011-05-09 09:30:21
json_encode手册非常清楚它的用法,请查看http://ar.php.net/manual/en/function.json-encode.php中的'Example #2A json_encode() example showing the all options in action‘
json_encode将标准php数组转换为JSON。
无论如何,您的SQL代码是不正确的。必须使用mysql_fetch_array从results2中获取值,而查询中没有'short‘和'full’。
https://stackoverflow.com/questions/5931329
复制相似问题