Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>this is one way to achive your objective. </p> <pre><code>function calNumDays($numberOfDays){ $num_days = $numberOfDays; $days = ''; if($num_days == "31" || $num_days == "30" || $num_days == "29") { $num = $num_days; for($i=1; $i &lt;=$num; $i++) { $days .= '&lt;span class="day"&gt;' . $i . '&lt;/span&gt;'; } //removed foreach } } </code></pre> <p><strong>Update</strong><br> Apologise the function is fine I just missed something from your Question. (Which explains the down vote.</p> <p>Your problem is that you are creating the whole thing in the while loop, so the days that are appended from the last call are also appended to the next output.</p> <p><strong>Update</strong></p> <p>Updated the calNumDays function above (removed the array output) <br> below is the code that should now do as you need.</p> <pre><code>$tmpArray = array(); if($sql_month_days &gt; 0) { while($row = mysql_fetch_array($sql_month_days)) { array_push($tmpArray, $row); } } foreach($tmpArray as $k){ $monthDays .= '&lt;div id="monthContainer"&gt;&lt;span class="monthName"&gt;'. $k['name'] .'&lt;/span&gt;&lt;div class="monthDaysContainter"&gt;'. calNumDays($k['num_days']).'&lt;/div&gt;&lt;/div&gt;'; } </code></pre> <p><strong>Update</strong> <br>Should you wish to keep what you already have -- (and i may have over complicated it) --</p> <pre><code>if($num_days === "31") { $days = ''; for($i=1; $i &lt;=31; $i++) { $days .= '&lt;span class="day"&gt;' . $i . '&lt;/span&gt;'; } } else { if($num_days === "30") { $days = ''; for($i=1; $i &lt;=30; $i++) { $days .= '&lt;span class="day"&gt;' . $i . '&lt;/span&gt;'; } } else { if($num_days === "29") { $days = ''; for($i=1; $i &lt;=29; $i++) { $days .= '&lt;span class="day"&gt;' . $i . '&lt;/span&gt;'; } } } } </code></pre> <p>You only really to need to reinitialize the <code>$days</code> before each <code>for</code> after the <code>if</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload