开发者

Trouble displaying variable in foreach loop using multidimentional array

I'm able to display id and tags in the foreach loop no problem. But I'm having trouble showing title and height. I'm not sure how to call them into the foreach loop.

I can call them in the while loop so I know that they are working.

$persons = array();
$tags = array();

while( ($row = mysqli_fetch_array( $rs, MYSQLI_ASSOC)))
{
    if(!isset( $persons[$row['id']]))
    {
        $persons[$row['id']]['title'] = $row['title'];
        $persons[$row['id']]['height'] = $row['height'];
        $persons[ $row['id'] ] = array( 'id' => $row['id'], 'tag' => $row['tag']);
        $tags[ $row['id'] ] = array();
    }
    $tags[ $row['id'] ][] = $row['tag'];
}

foreach( $persons as $pid => $p)
{
    echo开发者_开发技巧 'id: # ' . $p['id'] ;
    echo 'title: ' . $p['title'];
    echo 'height: ' . $p['height'];
    echo '<a href="#">' . implode( '</a>, <a href="#">', $tags[ $p['id'] ])  . '</a>';
    echo '<br /><br />';
}


You're overwriting $persons[ $row['id'] ] when you set the tags, so you lost the other data.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜