Hi,
Based on the data below, I want to create a list/table with the data that ends up in the array. However, I can't figure it out and I have tried everything regarding array format, count, etc.
I hope it's clear because I can't figure it out. As an example (from Excel);
Code:
Participants Category
20 Boklam
12 Jeugbok
6 Jongerebok
9 Ouderebok
2 Veteranenbok
60 Geitlam
30 Jeugdgeit
20 Jongeregeit
15 Ouderegeit
5 Veteranengeit
This is my query (where $id = 24);
Code:
SELECT show_participants.*,
zoo_easy.Gender,
zoo_easy.Born,
zoo_easy.Name,
zoo_easy.OwnerName
FROM show_participants,
zoo_easy
WHERE show_participants.participant_show = ' . $id . '
AND show_participants.participant_animal = zoo_easy.RegistrationNumber
ORDER BY zoo_easy.Gender,
zoo_easy.Born DESC
And this is the result I get from print_r;
Code:
Array
(
[0] => Array
(
[participant_id] => 106
[participant_animal] => A22035
[participant_show] => 24
[participant_category] => 4
[Gender] => Bok
[Born] => 2022-03-10
[Name] => Abel van de Zwartberg
[OwnerName] => B. Segers Bert
)
[1] => Array
(
[participant_id] => 105
[participant_animal] => NN24-195
[participant_show] => 24
[participant_category] => 2
[Gender] => Geit
[Born] => 2024-03-18
[Name] => Pearl van de Pijpjes
[OwnerName] => S.H. Dekker
)
[2] => Array
(
[participant_id] => 104
[participant_animal] => NN24-195
[participant_show] => 24
[participant_category] => 3
[Gender] => Geit
[Born] => 2024-03-18
[Name] => Pearl van de Pijpjes
[OwnerName] => S.H. Dekker
)
[3] => Array
(
[participant_id] => 103
[participant_animal] => A23001
[participant_show] => 24
[participant_category] => 2
[Gender] => Geit
[Born] => 2023-01-01
[Name] => Mit van het Heieinde
[OwnerName] => B. Van den Broeck Ben
)
)
This is the helper that's calculates the Category for me;
PHP Code:
<?php
use App\Models\CategoriesModel;
use CodeIgniter\CodeIgniter;
function getCategory($data)
{
$categoriesModel = new CategoriesModel();
$gender = $data['Gender'];
$born = substr($data['Born'], 0 ,4);
$year = date("Y");
$count = date("Y") - substr($data['Born'], 0 ,4);
// Lam
if ($count == 0)
{
$sql = $categoriesModel->getCategoryData('1');
$result = $gender . strtolower($sql['category_name']);
}
// Jeugd
if ($count == 1)
{
$sql = $categoriesModel->getCategoryData('2');
$result = $sql['category_name'] . strtolower($gender);
}
// Jongere
if ($count == 2)
{
$sql = $categoriesModel->getCategoryData('3');
$result = $sql['category_name'] . strtolower($gender);
}
// Oudere
if ($count == 3 OR $count == 4 OR $count == 5)
{
$sql = $categoriesModel->getCategoryData('4');
$result = $sql['category_name'] . strtolower($gender);
}
// Veteraan
if ($count >= 6)
{
$sql = $categoriesModel->getCategoryData('5');
$result = $sql['category_name'] . strtolower($gender);
}
// Error handling
if (empty($result))
{
$result = 'Onjuiste data';
}
return $result;
}
I hope someone can help me, because I've been stuck on this for several days now and running out of time. I can't and do not want to change anything in the zoo_easy table. This is loaded using a CSV file because it comes from a different system.
Cheers.
<?php echo "Programming and perfectionism sucks sometimes..."; ?>