Re: Array problem

From: Date: Wed, 17 Oct 2007 11:53:17 +0000
Subject: Re: Array problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-263260@lists.php.net to get a copy of this message
2007. 10. 17, szerda keltezéssel 13.08-kor Merlin ezt írta: > Hi there, > > I am pulling picture ids out of a db and comment ids. The comments > belong to the pic ids and are stored in two seperate tables. > I am having trouble with the arrays to display them after pulling out of > the db. > > The data is filled like this: > > while (rows etc.){ > $comment_id[$row->pic_id][] = $row->comment_id; > } > > The goal is to cycle through that array and display the picture followed > by the belonging comments: > > Picture ID 1 > -Comment 1 to pic_id 1 > -Comment 2 to pic_id 1 > -Comment 3 to pic_id 1 > > Picture ID 2 > -Comment 1 to pic_id 2 > -Comment 2 to pic_id 2 > > That does sound easy, but unfortunatelly I could not figure it out so far. > > Can somebody give me a hint on how to cycle throug the arrays, or an > alternative way to achive my goal? something like $pic_ids = array_keys($comment_id); foreach ($pic_ids as $pic_id) { // echo image tag or what you want foreach ($comment_id[$pic_id] as $comment) { // echo comment or what you want } } greets Zoltán Németh > > Thank you for any help. > > Best regards, Merlin >

« previous php.general (#263260) next »