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

  • SEARCH
  • Home
  • 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 6557189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:02:34+00:00 2026-05-25T13:02:34+00:00

I need some help figuring out this for loop logic. I know exactly what

  • 0

I need some help figuring out this for loop logic. I know exactly what I want to do, but I sadly can’t seem to get to it.

This is my code at the moment.

<? foreach($ticket_details as $ticket): ?>
  <tr class="tableBG" style="background-color: #fc6">
    <td align="center"><?= $ticket['name']; ?></td>
    <td align="center"><?= $ticket['price']; ?></td>
    <td align="center"><?= $ticket['priceWithinAllocation']; ?></td>
    <? for($i = 0; $i < $event_details['number_of_days']; $i++): ?>
      <? 
      foreach($ticket['days'] as $key => $value)
      {
        if($value == date('Y-m-d', strtotime($event_details['startDate'] . "+ $i day")))
        {
          echo "<td>&#10003;</td>";
        }
        else
        {
          echo "<td>--</td>";
        } 
      }
      ?>
    <? endfor; ?>
    <td align='center'>
      <input type='button' class='remove' id='remove[ticket][<?= $ticket['ticketID'] ?>]'  value='REMOVE' />
    </td>
  </tr>
<? endforeach; ?>

This doesn’t really work.

My tickets array looks like this:

    [5] => Array
    (
        [ticketID] => 5
        [eventID] => 1
        [name] => Thu
        [price] => 500
        [priceWithinAllocation] => 250
        [day] => 2011-08-25
        [days] => Array
            (
                [0] => 2011-08-25
            )

    )

[6] => Array
    (
        [ticketID] => 6
        [eventID] => 1
        [name] => Wed+Thu
        [price] => 900
        [priceWithinAllocation] => 110
        [day] => 2011-08-24
        [days] => Array
            (
                [0] => 2011-08-24
                [1] => 2011-08-25
            )

    )

When $ticket['days'] contains more than one value, it prints out too many empty (–) <td>. I’m not sure how to do the loop without having it print more than I need. Here’s a screenshot of what happens with this code:
this makes me cry

I tried some stuff with if(count($ticket['days'])) { } but that didn’t work out. So now I’m stuck.

I realise this is a fairly vague question because I didn’t provide too much code here; if needed, I can provide more, but there’s a lot of stuff going on so I kept it to a minimum.

Thanks in advance.

  • 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-05-25T13:02:34+00:00Added an answer on May 25, 2026 at 1:02 pm

    You print a cell for each date in $ticket[‘days’]. That’s why you get too much cells.

    Try this :

    <? foreach($ticket_details as $ticket): ?>
      <tr class="tableBG" style="background-color: #fc6">
        <td align="center"><?= $ticket['name']; ?></td>
        <td align="center"><?= $ticket['price']; ?></td>
        <td align="center"><?= $ticket['priceWithinAllocation']; ?></td>
        <? for($i = 0; $i < $event_details['number_of_days']; $i++): ?>
          <? 
          $foundDate = false;
          foreach($ticket['days'] as $key => $value)
          {
            if($value == date('Y-m-d', strtotime($event_details['startDate'] . "+ $i day")))
            {
              $foundDate = true;
            }
          }
          if($foundDate)
          {
            echo "<td>&#10003;</td>";
          }
          else
          {
            echo "<td>--</td>";
          } 
          ?>
        <? endfor; ?>
        <td align='center'>
          <input type='button' class='remove' id='remove[ticket][<?= $ticket['ticketID'] ?>]'  value='REMOVE' />
        </td>
      </tr>
    <? endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some php help in figuring out how use this array I created, but
I need some help figuring out and SQL Statement. I know what I want
I'm a n00b and I need some help figuring out this issue, I would
I need some help figuring this out. I am trying to create a function
I am having an absolute headache figuring this out. I badly need some help
I need some help figuring out why the following scenario does not work. I'm
Hey all, i am in need of some help with figuring out how to
I'm looking to implement the Shunting-yard Algorithm , but I need some help figuring
I need some help with figuring out Pythons *args and **kwargs . It's simple
I need help figuring out some regular expressions. I'm running the dig command and

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.