I am writing a program and here is what it is doing...
I have an array of "members" in a group. I am looping through this array, (the array is their member_id), it then goes out to a class to get the member id, and then for each member, the events they are entered in.
It is only actually returning the first entrant name and the first event, although it is hitting the class function each time. Do you have any clue what would cause this?
I appreciate any help or advice. I have literally been struggling with this for hours. Tried using straight functions and not classes and that did not work either, so I must be doing something really stupid.
Server is using php 4.3
Thanks!
Here is what the output (in bold hopefully) looks like. The code is an output of sql string that is called when the class is called to prove it is reaching the class. When I manually run the sql queries directly in the database they work, so I don't think it is failed queries. Below that, I have the class snippet and code that calls the class...
ENTRANTS:
CODE: SELECT first_name, last_name FROM users WHERE user_id = '18'
John Doe
CODE: SELECT description FROM event WHERE id =1
Bareback
CODE: SELECT description FROM event WHERE id =2
Second event entered in
CODE: SELECT first_name, last_name FROM users WHERE user_id = '2779'
This is where the name of entrant 2 would display
CODE: SELECT description FROM event WHERE id =1
event entered in would go here
CODE: SELECT description FROM event WHERE id =3
event entered in would go here
CODE: SELECT description FROM event WHERE id =5
event entered in would go here
CODE: SELECT first_name, last_name FROM users WHERE user_id = '3947'
This is where the name of entrant3 would display
CODE: SELECT description FROM event WHERE id =3
event entered in would go here
CODE: SELECT description FROM event WHERE id =2
event entered in would go here
CODE: SELECT description FROM event WHERE id =5
Code that calls the class....
echo "<br><b>ENTRANTS:</b><br>";
for($j=0;$j<count($group_members);$j++){ #loop through the array and perform action
$group_member = $group_members[$j];
$group_member_array[] = $group_member;
if($group == 'yes'){
$db->get_first_last($group_member);
}
#Get performance events to enter array
$variable = "performance_events".$group_member;
$number =count($$variable);
foreach ($$variable as $event_id) {
$event_description = $db->event_description($event_id);
echo "<li> $event_description</li>";
}
Class code for each:
#--------------------------------------------------------------------------------
NEW FUNCTION
function get_first_last($entrant_id){
$SQLstr = "SELECT first_name, last_name FROM users WHERE user_id = '$entrant_id' ";
$this->results = mysql_query($SQLstr);
list($first, $last) = mysql_fetch_row($this->results);
$name = "$first $last";
echo "$name";
return $name;
}
END FUNCTION
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
NEW FUNCTION
function event_description($event_id){
$SQLstr = "SELECT description FROM event WHERE id =$event_id";
$this->results = mysql_query($SQLstr);
if($this->results > 0){
list($description) = mysql_fetch_row($this->results);
$description = $description;
} #end if
return $description;
}
END FUNCTION
#--------------------------------------------------------------------------------