Ben hangi arsa aynı yaşta diğer üyeleri için ortalama yüksekliği karşı yüksekliğinde bir üyenin değişiklik grafikler oluşturmak için gereken bazı döngü mantığı ile mücadele ediyorum. Veriler, aşağıdaki gibi yapılandırılmıştır:
A member can have many visits. Each visit belongs to a member (ref member_id). A visit can have more than one height entry Heights belong to a visit.
Ben (bir ORM kullanarak) ile aşağıdaki bir üyenin yükseklikleri erişebilirsiniz:
$data = array();
foreach ($this->member->visits as $v)
{
foreach ($v->heights as $h)
{
$data[] = $h->height;
}
}
Bir üye yalnızca 2 kez varsa, ben bu ziyaretler sırasında üyenin yaşını öğrenmek ve üyesinin yaşına karşı yükseklik bilgileri saklamak gerekir. Sadece bu yaş (örneğin 14 ve 15 yaş) kullanarak, ben onlar bu yaşlarda da vardı, diğer üyelerin ortalama yüksekliği çalışmak gerekir. Ben sorun bu mantık hakkına sahip oluyor, ama burada benim eksik ve yanlış kod ediyorum - Birisi yardım eder!
$ages = array();
//get all entries belong to current member
foreach ($this->member->visits as $v)
{
//get all heights belonging to this entry
foreach ($v->member_heights as $h)
{
//calculate member's age at time of this entry and add to array
$ages[] = member::years($v->updated, $v->member->dob);
}
}
$data = array();
//get all
$visits = ORM::factory('visit')->find_all();
//run through each of the ages which the current member has a height entry for
foreach ($ages as $age)
{
//need to run through all of the data entries
foreach ($visits as $v)
{
//look at entries with member heights entered
foreach ($v->member_heights as $h)
{
$others_ages[] = member::years($v->updated, $v->member->dob);
}
}
}
EDIT: to try and expand on this and explain a bit better, I have the following function which correctly collates and outputs the member's height and the age they were at that time. I need to try and use the $ages array to generate the average height of all other members for a comparison. Hope this makes more sense!
public function height()
{
$data = array();
//build format required for highcharts output
foreach ($this->member->visits as $v)
{
foreach ($v->heights as $h)
{
$data[] = $h->height;
//this calculates the age at the time of the entry
$ages[] = member::years($v->updated, $v->member->dob);
}
}
echo json_encode($data);
echo json_encode($ages);
}