开发者

array showing same index?

At the top using this $alert['new_msg'] i am getting this array.

Array
(
    [0] => Array
        (
            [mes_id] => 1990
            [mem_id] => 51
        )

    [1] => Array
        (
            [mes_id] => 1880
            [mem_id] => 51
        )

)

I want to take mem_id . But when i apply this foreach loop

 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 is just a simple function which gives me result but at the end I am getting like this

Array
(
    [alerttitle] => 
    [alertImageUrl] => 
    [alertDescription] =>开发者_StackOverflow社区 (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
)

So i am confused if i am sending 2 array hw the result is coming as 3.

please help thanks


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜