在顶部使用这个$ alert ['new_msg']我得到了这个数组。
Array
(
[0] => Array
(
[mes_id] => 1990
[mem_id] => 51
)
[1] => Array
(
[mes_id] => 1880
[mem_id] => 51
)
)
我想带mem_id。但是当我应用这个foreach循环时
if(isset($alert['new_msg'])){
$msg = array();
foreach ($alert['new_msg'] as $kk => $result) {
$from = $alert['new_msg'][$kk]['mem_id'];
$sql = "SELECT profilenam,photo_thumb FROM members WHERE mem_id='$from'";
$rrslt = execute_query($sql, false);
$msg['alerttitle']=$rrslt[$kk]['profilenam'];
$msg['alertImageUrl']=$rrslt[$kk]['photo_thumb'];
$msg['alertDescription']= "(".$rrslt['count'].")"." New Message(s)";
$msg['alertType']= "New Message";
$msg['count']= $rrslt['count'];
$msg['id']= $from ;
}
return $msg;
}
execute_query只是一个给我结果的简单函数 但最后我变得像这样
Array
(
[alerttitle] =>
[alertImageUrl] =>
[alertDescription] => (1) New Message(s)
[alertType] => New Message
[count] => 1
[id] => 51
)
Array
(
[alerttitle] =>
[alertImageUrl] =>
[alertDescription] => (1) New Message(s)
[alertType] => New Message
[count] => 1
[id] => 51
)
Array
(
[alerttitle] =>
[alertImageUrl] =>
[alertDescription] => (1) New Message(s)
[alertType] => New Message
[count] => 1
[id] => 51
)
所以我很困惑,如果我发送2阵列hw,结果是3。
请帮忙 感谢
答案 0 :(得分:0)
if(isset($alert['new_msg'])){
$return = array();
foreach ($alert['new_msg'] as $kk => $result) {
$from = $result['mem_id'];
$dbResults = mysql_query("SELECT profilenam,photo_thumb FROM members WHERE mem_id='$from'");
$count = mysql_num_rows($dbResults);
$rrslt = mysql_fetch_assoc($dbResults);
$msg['alerttitle']=$rrslt['profilenam'];
$msg['alertImageUrl']=$rrslt['photo_thumb'];
$msg['alertDescription']= "(".$count.") New Message(s)";
$msg['alertType']= "New Message";
$msg['count']= $count;
$msg['id']= $from ;
$return[] = $msg;
}
return $return;
}