在我的数据库中,我有不同的用户名:" fabio97"," antonino"," lauretta"。我想让他们从DB获得这样的数组:
$dati = array("str"=>array("n1"=>"fabio97", "n2"=>"antonino", "n3"=>"lauretta"));
是否正确写:
...
"str" => array("n".$i=>"Ti sei incrociato con ".$array_db[username]),
...
进入循环
...
$i = 0;
$array_user = mysql_fetch_array($query);
while ($array_db = mysql_fetch_array ($query_db)) {
...
if ($array_user[square] == $array_db[square]) {
$dati = array(
"data" => array(
'address_complete'=>$data->results[0]->formatted_address,
'address_square'=>$data->results[0]->address_components[1]->long_name,
'location'=>$data->results[0]->address_components[2]->long_name,
'postal_code'=>$data->results[0]->address_components[7]->long_name,
'data_ora'=>$tmp_date
),
"str" => array("n".$i=>"Ti sei incrociato con ".$array_db[username]),
"index" => $i
);
$i++;
}
}
并用Ajax调用它们:
... success:function(msg){
if(msg){
$("#location").html(Object.keys(msg.str).map(x => msg.str[x]).join(", "));
}else{
$("#location").html('Not Available');
}