php & css divs .. how to get every fourth div with a little space after it..

Hi all,

Hopefully someone can help me, I am stumped.

I have function that delivers a series of different css divs (each a little blob), one after the other, horizontally, This works :slight_smile: What is missing is I want a little space after every fourth div/blob.

It is a little calendar, 4 blobs for each week, some different colours depending on what the team is doing on that week.

so visually it looks like several rows of blobs:
team 1 : blob blob blob blob redblob redblob blob blob etc
team 2 : blob redblob redblob blob blob blob etc
.
.
teamn:

background :
mainfunctionA. Contains a query that takes lots of data from MYSQL, using the usual while loop.

functionB. A little calendar made up of little blobs, one blob for each week (so 48 blobs), these blobs are just two little divs, one no colour div = a, the other red div = b.

The functionCalendar delivers the blobs :). I am pretty sure it is delivering them as a string, but I cant seem to split or number each div so I can take every 4th one and put a space… Ive tried the string functions array functions… maybe this is the wrong approach… the third day of playing around with it and my brain is in a gridlock… any help appreciated. :slight_smile:


function calendar() {

global $fundays; // global variable from mainfunctionA, use 90 in this example.

$startdate = 1;

// we want a firstdate fd- which I can change through input field, for now we just say 30days
$firstdate = 30;

for ($day = 1; $day <= $firstdate / 7.5 ; $day++) {
$div = “<div id = “boxcal1” >” ; // no colour blob
echo $div ;
}

for ($day = 1; $day <= $fundays / 7.5 ; $day++) {
$div = “<div id = “boxcal2” >” ; // colour blob
echo $div;
}

$totaldays = (($firstdate + $fundays) / 7.5) ;

$totaldaysleft = ((360 / 7.5) - $totaldays) ;

$day = $totaldaysleft;

for ($day = 1 ; $day <= $totaldaysleft ; $day++) {
$div = “<div id = “boxcal1” >” ; // no colour blob
echo $div ;
}

I call the function in the mainfunctionA as follows:

$mindays = $row[‘min_time_days’] ;
global $mindays;
$getCalendar = calendar();

try using something like this:

[php]

<?php function calendar() { global $fundays; $startdate = 1; $firstdate = 30; for ($day = 1; $day <= $firstdate / 7.5 ; $day++) { $div = "
" ; // no colour blob echo $div ; //the '%' function finds the remainder of a sum, //therefore only when the day is divisible by 4 will a space be added $mod = $day % 4; if($mod == "0") { echo " "; } } for ($day = 1; $day <= $fundays / 7.5 ; $day++) { $div = "
" ; // colour blob echo $div; $mod = $day % 4; if($mod == "0") { echo " "; } } $totaldays = (($firstdate + $fundays) / 7.5) ; $totaldaysleft = ((360 / 7.5) - $totaldays) ; $day = $totaldaysleft; for ($day = 1 ; $day <= $totaldaysleft ; $day++) { $div = "
" ; // no colour blob echo $div ; $mod = $day % 4; if($mod == "0") { echo " "; } } } ?>

[/php]

Hi,
Thanks a lot :slight_smile: and apologies for this late thankyou.

The reason its a little late is I changed the whole thing from a string to one array with consecutive keys (took me quite a while to work out). Then I used your code to find the keys divisible by 4 and add a blankdiv. I had to do a little jiggery pockery because the first key was a 0 so I was getting a blankdiv after 0 because 0/4 = 0… anyway its ok now.

Thank you again for steering me in the right direction.

//manually created two arrays $div1 & $div2 containing the cal1 and cal2 divs

// 3 of these - for $div1 , $div2 and $div1 arrays - the final $divone contains all keys and elements.
for ($day = 1; $day <= $firstdate ; $day++) {

foreach ($div1 as $key => $value) {
}
$divone[] = $div1[$day];
}

// walk through $divone, looking for keys divisible by 4
foreach ($divone as $key => $value) {

if((($key == “0”) || ($key % 4 != “0”))) {
print $value ;
} else {
echo " <div id = “cal3” > ";
print $value;
}
}

Sponsor our Newsletter | Privacy Policy | Terms of Service