Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:55:46+00:00 2026-06-07T06:55:46+00:00

I’m trying to dynamically create 5 divs that represent 5 days of the week.

  • 0

I’m trying to dynamically create 5 divs that represent 5 days of the week. In each div, I’m trying to loop through data fetched from my code igniter model and echo a series of un-ordered list based upon a project, a date, and tasks that are related to that project. I’m fetching the data from both my project table, to echo the project name in h4 tags, and from the task table, to echo related task under the project h4. The problem I’m having is that I can’t seem to find a way to prevent my algorithm from repeating project names and related tasks. In other words, if there’s two tasks related to one project, that project and the two related tasks will be echoed out twice. Here’s an image to help explain the problem:

enter image description here

    <?php for($counter = 0; $counter < 5; $counter++): ?><!-- loops through and creates divs -->
        <?php 
          $date = date("F j, Y");
          $refDate = date("Y-m-d");
          $counterForLi = 0;
        ?>
                  <div class="span2 check-list date-container">
                    <div id="form-to-date">
                      <div class="replace">

                      <h2 class="day"></h2>
                        <h4 class="thedate">
                          <?php
                            if ($counter > 0) {
                              $tomorrow = mktime(0, 0, 0, date("m"), date("d")+$counter, date("y"));
                              $refDate = date("Y-m-d", $tomorrow);
                              $date = date("F j, Y", $tomorrow);
                              echo $date;
                            } else {
                              echo $date;
                            }
                          ?>
                        </h4>
                        <input type="hidden" name="thedate" class="hidden-date" value="<?php echo $refDate; ?>">

                            <?php if(isset($tasks)) : foreach($tasks as $taskRow) :?> <!-- loop through the tasks -->
                              <?php if($taskRow->dateadded == $refDate) : ?> <!-- in the context of the right date -->
                                <?php if(isset($taskRow->_project_fk)) : ?>
                                    <?php
                                        $relatedProjectId = $taskRow->_project_fk;
                                        $relatedProjectName = NULL;
                                        if(!isset($relatedProjectName)) {
                                            foreach ($projects as $ProjectRow) {
                                                if ($ProjectRow->__project_pk == $relatedProjectId) {
                                                    $relatedProjectName = $ProjectRow->project_name;
                                                    echo "<h4>" . $relatedProjectName . "</h4>";
                                                echo "<ul>";
                                                }
                                            }

                                        foreach ($tasks as $task) {
                                          if ($task->_project_fk == $relatedProjectId && $task->dateadded == $refDate) {
                                            echo "<li>".$task->task_name."</li>";
                                          }

                                        }
                                        echo "</ul>";
                                    } 


                                    ?>

                                <?php endif; ?>

                              <?php endif; ?>

                            <?php endforeach; ?>

                            <?php endif; ?>

                          </ul>
                        </div><!-- /replace -->
                      </div><!-- /form-to-date -->
                    </div>
    <?php endfor; ?>

I realize this code is kind of a mess so if you need clarification, please ask.

Edit:
Here’s the structure of my tasks array
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:55:48+00:00Added an answer on June 7, 2026 at 6:55 am

    Start by creating a hierarchical array structure that groups tasks by project and date. From your example and data structure it looks like each task belongs to one project and was started on one date. For each date, you want to show each project that had at least one task that started on that date along with those tasks that started on that date.

    $tasksByProjectAndDate = array();
    foreach ($tasks as $task) {
        $tasksByProjectAndDate[$task->dateadded][$task->_project_fk][] = $task;
    }
    

    Next create a map from project ID (PK) to the project. This makes looking up each project’s name faster since you loop over all projects only once.

    $projectsById = array();
    foreach ($projects as $project) {
        $projectsById[$project->__project_pk] = $project;
    }
    

    Finally, you’re ready to build your UI. I’ll leave fitting it into HTML up to you and just output a simple text view. The logical flow will be identical.

    foreach ($tasksByProjectAndDate as $date => $tasksByProject) {
        echo "$date\n";
        foreach ($tasksByProject as $projectId => $tasks) {
            $project = $projectsById[$projectId];
            echo "  $project->project_name\n";
            foreach ($tasks as $task) {
                echo "    $task->task_name\n";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.