NYCPHP Meetup

NYPHP.org

[nycphp-talk] Trouble with Array of Objects

Malcolm, Gary gmalcolm at professionalcredit.com
Tue May 27 17:16:20 EDT 2003


oh never mind i see it....

> -----Original Message-----
> From: Christopher R. Merlo [mailto:cmerlo at turing.matcmp.ncc.edu]
> Sent: Tuesday, 27 May, 2003 2:01 PM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] Trouble with Array of Objects
> 
> 
> On 2003-05-27 16:50 -0400, Bhulipongsanon, Pinyo 
> <Pinyo.Bhulipongsanon at usa.xerox.com> wrote:
> 
> > for ( $i = 0 ; $i <= 4 ; $i++ ) {
> >   $myArray[$i] = codeToCreateObject();
> > }
> > 
> > I am not sure if this will help?  Can I see your code?
> 
> I'll give you the highlights, and spare you most of the MySQL stuff.
> 
> Here's the class def:
> 
>   class Meeting {
> 
>   var $day;
>   var $start;
>   var $end;
>   var $dept;
>   var $course;
>   var $building;
>   var $room;
> 
>   function Meeting( $day, $start, $end,
> 		    $dept, $course, $section,
> 		    $building, $room ) {
>     $this->day = $day;
>     $this->start = $start;
>     $this->end = $end;
>     $this->dept = $dept;
>     $this->course = $course;
>     $this->building = $building;
>     $this->room = $room;
>     print "<p>" . $this->toString( ) . "</p>\
";
>   }
> 
>   function toString( ) {
>     return date( "g:i a", strtotime( $this->start ) ) . " to "
>       . date( "g:i a", strtotime( $this->end ) ) . ": $this->dept "
>       . "$this->course $this->section in $this->building $this->room";
>   }
> } // class Meeting
> 
> And here's the relevant code:
> 
> $meetings = array( );
> 
> // some more stuff
> 
>   foreach( $day_names as $day=>$name ) {
> 
>     $day_query = "select * from meetings where id = 
> \\"{$sec_row[ "$day" ]}\\"";
>     $day_result = @mysql_query( $day_query );
> 
>     $day_row = @mysql_fetch_assoc( $day_result );
>     if( !is_null( $day_row[ 'start' ] ) ) {
> 
>       $meetings[ $meeting_count ] =
>         new Meeting( $name, $day_row[ 'start' ], $day_row[ 'end' ],
>                        $course_row[ 'dept' ], $course_row[ 'course' ],
>                        $sec_row[ 'section' ], $day_row[ 'building' ],
>                        $day_row[ 'room' ] );
>       $meeting_count++;
>     }
>   }
> }
> 
> Here's what I get on the page.  First, the results of the constructor
> being called five times:
> 
> 8:00 am to 10:50 am: CMP 103 in B 113
> 
> 8:00 am to 10:50 am: CMP 103 in B 119
> 
> 8:00 am to 10:50 am: CMP 103 in B 113
> 
> 8:00 am to 10:50 am: CMP 103 in B 119
> 
> 8:00 am to 10:50 am: CMP 218 in B 113
> 
> And then the result of print_r( $meetings ):
> 
> Array ( [4] => meeting Object ( [day] => Friday [start] => 08:00:00
> [end] => 10:50:00 [dept] => CMP [course] => 218 [building] => B [room]
> => 113 ) ) 
> 
> And I'm at a loss.
> 
> -- 
> cmerlo at turing.matcmp.ncc.edu        
> http://turing.matcmp.ncc.edu/~cmerlo
> 
> We're sorry, but the number you have dialed is imaginary.  Please
> rotate your phone ninety degrees and try again.  Thank you.
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030527/79e76d2a/attachment.html>


More information about the talk mailing list