Php Jquery获取mysql值作为数组

Php Jquery获取mysql值作为数组,php,jquery,mysql,arrays,Php,Jquery,Mysql,Arrays,即使我在谷歌上搜索了这么多,我似乎也不可能做到这一点 我有一个mysql表,我需要将一列中的值返回到我的jquery脚本中,如下所示: array = 123, 556, 553, 542, 4322... 我要么这样理解: array = "123""556""553""542""4322"... [123, 556, 553, 542, 43222, ...] 还是像这样 [{"FB_ID":"123"}, {... 如何使用php或jquery实现这一点 这是我当前的代码,结果看

即使我在谷歌上搜索了这么多,我似乎也不可能做到这一点

我有一个mysql表,我需要将一列中的值返回到我的jquery脚本中,如下所示:

 array = 123, 556, 553, 542, 4322...
我要么这样理解:

array = "123""556""553""542""4322"...
[123, 556, 553, 542, 43222, ...]
还是像这样

[{"FB_ID":"123"}, {...
如何使用php或jquery实现这一点

这是我当前的代码,结果看起来像上一个

$connection = mysql_connect("$host", "$username", "$password") or die(mysql_error()); 

$sql = "SELECT FB_ID FROM `database`.`players` WHERE recieved = '1'";
$result =mysql_query($sql);


$rows = array();
while($r = mysql_fetch_assoc($result)) {
    $rows[] = $r;
  }

echo json_encode($rows);
尝试强制转换为int:

$rows[]=(int)$r['FB_ID'];

如果您希望这样:

array = "123""556""553""542""4322"...
[123, 556, 553, 542, 43222, ...]
这样做:

$rows = array();
while($r = mysql_fetch_assoc($result)) {
    $rows[] = $r['FB_ID'];
}

需要指定一个键来获取其值

while($r = mysql_fetch_assoc($result)) {
    $rows[] = $r['FB_ID'];
}
在php页面中

header("Content-type: application/json"); 
$arr = array(123, 556, 553, 542, 4322);
echo json_encode($arr);
在jquery中

$.ajax({
url:'yoururl',
type:'post',
dataType:'json',
success:function(result){
  var response    = JSON.stringify(result); 
  res             = JSON.parse(response);
  console.log(res);
}
});