RE: [PHP] Array problem

This is a discussion on RE: [PHP] Array problem within the PHP General forums, part of the PHP Programming Forums category; On 17 October 2007 12:09, Merlin wrote: > Hi there, > > I am pulling picture ids out of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-17-2007
Ford, Mike
 
Posts: n/a
Default RE: [PHP] Array problem

On 17 October 2007 12:09, Merlin wrote:

> 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 this should work:

foreach ($comment_id as $pic_id=>$comment_ids):
echo "Start of information for picture $pic_id";
foreach ($comment_ids as $com_id):
echo "Comment $com_id for picture $pic_id";
endforeach;
endforeach;

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 812 4730 Fax: +44 113 812 3211


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:51 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0