--- In php-list@yahoogroups.com, "Michael Sullivan" <[EMAIL PROTECTED]> wrote: > > --- In php-list@yahoogroups.com, "Michael Sullivan" <michael@> wrote: > > > > I have a problem. I'm working on an auto-schedular for my college's > > Music Festivals. I just started on this tonight. I'm starting by > > reading all the information into variables. For starters, I have a > > School class. The script should read data from the database into > > School objects for later use. I've never used objects in PHP before, > > but I've used them in several other languages. I read data from the > > database into the School objects using a loop, with a loop invariant > > called $schoolCount. I created a print statement so that I could see > > if the data was being correctly assigned to the School objects, but I > > think it's printing the value of the loop invariant instead of the > > school name like I want. I'm not sure why. Here's my code: > > > > <? > > //Now for some database stuff. > > $db = "NEO_Music_Festival"; > > $user = "festival"; > > $pass = [CENSORED]; > > //Let's connect > > $link = mysql_connect ("localhost", $user, $pass); > > if (!$link) die ("Could not connect to database server."); > > mysql_select_db ($db, $link) or die ("Could not connect to database"); > > > > class School > > { > > var $directorid; > > var $beginTimeReq; > > var $endTimeReq; > > var $schoolname; > > var $schoolid; > > var $accompanist = Array(); > > } > > > > class Accompanist > > { > > var $directorid; > > var $accid; > > var $accname; > > var $soloCount; > > var $ensembleCount; > > var $choirCount; > > var $showChoirCount; > > } > > > > class Room > > { > > var $roomNumber; > > var $entryTypeAccepted; //Solo-ensemble, choir, or show choir > > var $time = Array(); //Array of times > > } > > > > //Time to get started. > > > > $schoolCount = 0; > > $school = array(); > > > > $query = "SELECT director_id, school_id, school_name, > > choir_beg_time_req, choir_end_time_req FROM School ORDER BY school_id;"; > > $schoolresult = mysql_query($query, $link) or die ("Could not access > > database: ".mysql_error()); > > while ($school_row = mysql_fetch_array($schoolresult, MYSQL_ASSOC)) > > { > > $school[$schoolCount] = new School(); > > $school[$schoolCount]->$directorid = $school_row['director_id']; > > $school[$schoolCount]->$begTimeReq = > $school_row['choir_beg_time_req']; > > $school[$schoolCount]->$endTimeReq = > $school_row['choir_end_time_req']; > > $school[$schoolCount]->$schoolname = $school_row['school_name']; > > $school[$schoolCount]->$schoolid = $school_row['school_id']; > > print "School Name: ".$school[$schoolCount]->$schoolname."<br>\n"; > > > > $schoolCount++; > > } > > > <trimmed> > > My wife just pointed something out to me; Some of the numbers in > sequence are missing (like 4 and 10). This shows to me that what's > being printed is not in fact the loop invariant, but instead the value > of $school_row['school_id']. Why is it doing that when I asked to > print $school[$schoolCount]->$schoolname and this variable is supposed > to be set to $school_row['school_name'} as reflected in the above code??? >
No matter what member of $school[$schoolCount] I ask to have printed out, it always prints out the last value assigned to a variable of $school[$schoolCount]. Why would it do that?