Welcome Guest, Not a member yet? Register   Sign In
Array to HTML "Table"
#4
Bug 

So, after 9 hours i did came up with something temp. But it is ugly as f*.. I was erroring with the keys in the array because when it's empty i need some output and the maximum will always be 10. For now it's working but this is no-go for me. So if somebody has a decent and better solution. I love to hear!



This is the helper...

PHP Code:
function calculateParticipantsAtShow($data)
{
    $categoryModel = new CategoryModel();

    // COUNT 1
    if (!empty(array_count_values(array_column($data'participant_category'))['1']))
    {
        $count_1 array_count_values(array_column($data'participant_category'))['1'];
    }
    else
    {
        $count_1 0;
    }
    // COUNT 2
    if (!empty(array_count_values(array_column($data'participant_category'))['2']))
    {
        $count_2 array_count_values(array_column($data'participant_category'))['2'];
    }
    else
    {
        $count_2 0;
    }
    // COUNT 3
    if (!empty(array_count_values(array_column($data'participant_category'))['3']))
    {
        $count_3 array_count_values(array_column($data'participant_category'))['3'];
    }
    else
    {
        $count_3 0;
    }
    // COUNT 4
    if (!empty(array_count_values(array_column($data'participant_category'))['4']))
    {
        $count_4 array_count_values(array_column($data'participant_category'))['4'];
    }
    else
    {
        $count_4 0;
    }
    // COUNT 5
    if (!empty(array_count_values(array_column($data'participant_category'))['5']))
    {
        $count_5 array_count_values(array_column($data'participant_category'))['5'];
    }
    else
    {
        $count_5 0;
    }
    // COUNT 6
    if (!empty(array_count_values(array_column($data'participant_category'))['6']))
    {
        $count_6 array_count_values(array_column($data'participant_category'))['6'];
    }
    else
    {
        $count_6 0;
    }
    // COUNT 7
    if (!empty(array_count_values(array_column($data'participant_category'))['7']))
    {
        $count_7 array_count_values(array_column($data'participant_category'))['7'];
    }
    else
    {
        $count_7 0;
    }
    // COUNT 8
    if (!empty(array_count_values(array_column($data'participant_category'))['8']))
    {
        $count_8 array_count_values(array_column($data'participant_category'))['8'];
    }
    else
    {
        $count_8 0;
    }
    // COUNT 9
    if (!empty(array_count_values(array_column($data'participant_category'))['1']))
    {
        $count_9 array_count_values(array_column($data'participant_category'))['1'];
    }
    else
    {
        $count_9 0;
    }
    // COUNT 10
    if (!empty(array_count_values(array_column($data'participant_category'))['10']))
    {
        $count_10 array_count_values(array_column($data'participant_category'))['10'];
    }
    else
    {
        $count_10 0;
    }

    $result = array(
        // COUNT 1
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('1')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('1')['category_id'],
        'participantCategoryCount' => $count_1
        
),
        // COUNT 2
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('2')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('2')['category_id'],
        'participantCategoryCount' => $count_2
        
),
        // COUNT 3
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('3')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('3')['category_id'],
        'participantCategoryCount' => $count_3
        
),
        // COUNT 4
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('4')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('4')['category_id'],
        'participantCategoryCount' => $count_4
        
),
        // COUNT 5
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('5')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('5')['category_id'],
        'participantCategoryCount' => $count_5
        
),
        // COUNT 6
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('6')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('6')['category_id'],
        'participantCategoryCount' => $count_6
        
),
        // COUNT 7
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('7')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('7')['category_id'],
        'participantCategoryCount' => $count_7
        
),
        // COUNT 8
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('8')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('8')['category_id'],
        'participantCategoryCount' => $count_8
        
),
        // COUNT 9
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('9')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('9')['category_id'],
        'participantCategoryCount' => $count_9
        
),
        // COUNT 10
        array(
        'participantCategoryName' => $categoryModel->getShowCategoryById('10')['category_name'],
        'participantCategoryId' => $categoryModel->getShowCategoryById('10')['category_id'],
        'participantCategoryCount' => $count_10
        
)
    );

    return $result;


And in the view...
PHP Code:
<?php if(!empty($showCategories) AND !empty($showPartacipants)) : ?>
 <div class="row">
 <div class="col-md-12">
 <div class="row">
 <div class="col-md-12 mt-4">
 <table class="mb-5 mt-3 w-25">
 <thead>
 <tr>
 <th>Categorie</th>
 <th>Aantal</th>
 </tr>
 </thead>
 <tbody>
 <?php foreach($showCategories as $showCategorie) : ?>
 <?php $key $showCategorie['category_id'] - 1?>
 <tr>
 <td><?= $showCategorie['category_name'?></td>
 <td><?= calculateParticipantsAtShow($showPartacipants)[$key]['participantCategoryCount']; ?></td>
 </tr>
 <?php endforeach; ?>
 </tbody>
 </table>
 </div>
 </div>
 </div>
 </div>
 <?php endif; ?>
<?php echo "Programming and perfectionism sucks sometimes..."; ?>
Reply


Messages In This Thread
Array to HTML "Table" - by HarmW94 - 04-13-2024, 08:29 AM
RE: Array to HTML "Table" - by InsiteFX - 04-13-2024, 11:32 PM
RE: Array to HTML "Table" - by HarmW94 - 04-14-2024, 06:52 AM
RE: Array to HTML "Table" - by HarmW94 - 04-14-2024, 04:08 PM
RE: Array to HTML "Table" - by paulkd - 04-18-2024, 11:10 PM
RE: Array to HTML "Table" - by HarmW94 - 04-18-2024, 11:57 PM
RE: Array to HTML "Table" - by paulkd - 04-19-2024, 01:00 AM
RE: Array to HTML "Table" - by HarmW94 - 04-19-2024, 11:04 AM
RE: Array to HTML "Table" - by HarmW94 - 05-13-2024, 02:50 AM
RE: Array to HTML "Table" - by Bosborne - 05-14-2024, 03:28 AM
RE: Array to HTML "Table" - by paulkd - 05-13-2024, 10:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB