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++;
}

Here's what it's printing:

School Name: 1
School Name: 2
School Name: 4
School Name: 5
School Name: 6
School Name: 7
School Name: 8
School Name: 9
School Name: 11
School Name: 12
School Name: 13
School Name: 14
School Name: 15
School Name: 18
School Name: 19
School Name: 20
School Name: 21
School Name: 22
School Name: 23
School Name: 24
School Name: 25
School Name: 26
School Name: 27
School Name: 28
School Name: 29
School Name: 30
School Name: 31
School Name: 32
School Name: 33
School Name: 34
School Name: 35
School Name: 36
School Name: 37
School Name: 38
School Name: 39
School Name: 40
School Name: 41
School Name: 43
School Name: 46

Any hints?
?>


Reply via email to