PHP Whili loop problems

Dear PHP friends,

I have a calendar from the current month:

[php]
$vandaag = time();
$dag = date(“d”, $vandaag);
$maand = date(“m”, $vandaag);
$jaar = date(“Y”, $vandaag);

$begindag = mktime(0,0,0,$maand, 1, $jaar);
$maandnaam = date(‘m’, $begindag);

if($maandnaam == ‘01’){ $maandnaam = ‘Januari’; }
if($maandnaam == ‘02’){ $maandnaam = ‘Februari’; }
if($maandnaam == ‘03’){ $maandnaam = ‘Maart’; }
if($maandnaam == ‘04’){ $maandnaam = ‘April’; }
if($maandnaam == ‘05’){ $maandnaam = ‘Mei’; }
if($maandnaam == ‘06’){ $maandnaam = ‘Juni’; }
if($maandnaam == ‘07’){ $maandnaam = ‘Juli’; }
if($maandnaam == ‘08’){ $maandnaam = ‘Augustus’; }
if($maandnaam == ‘09’){ $maandnaam = ‘September’; }
if($maandnaam == ‘10’){ $maandnaam = ‘Oktober’; }
if($maandnaam == ‘11’){ $maandnaam = ‘November’; }
if($maandnaam == ‘12’){ $maandnaam = ‘December’; }

'.$maandnaam.' '.$jaar.'
';

$dagentellen = 1;
echo ‘

’;

while($blank > 0){
echo ‘

’;

$blank = $blank - 1;
$dagentellen++;
}

$dagen = 1;
while($dagen <= $dagenindemaand){

echo ‘

’;
$dagen++;
$dagentellen++;

if ($dagentellen > 7)
{
echo ‘

’;
$dagentellen = 1;
}
}
while($dagentellen >1 && $dagentellen <=7){
echo ‘’;
$dagentellen++;
}
echo’
Zo: Ma: Di: Wo: Do: Vr: Za:
’.$dagen.’
[/php]

Using a MySQL database I retrieve events, check out query below:

[php]
$query = “select day(datum) as dag, type from planning where
month(datum)= ‘$maand’ and
year(datum) = ‘$jaar’ and
type != ‘Overgeslagen bezoek’”;
$result = mysql_query($query)or die (“Query probleem”);
while($row = mysql_fetch_assoc($result)){
extract($row);
echo $dag;
}
[/php]

This gives result like 2 and 25.

How can I give thoses days from my database, a color into $dagen++

I only get weird result and infinite loops…

Thanks in advance
Treid Google, not my friend today.

if you just want one color then change this line;
[php]echo ‘

’.$dagen.’’;[/php]
to:
[php]echo ‘’.$dagen.’’;[/php]

or you can get tricky and do odds and evens:

[php]if ($dagen % 2) {
echo ‘

’.$dagen.’’;
} else {
echo ‘’.$dagen.’’;
}[/php]

Let me know if I understood you correctly and this is what you are looking for, or if it gives you ideas.

Dennis,
I think you do not understand the EXTRACT() command. I am sure you can not extract an array
from the results of a query into ITSELF! Look at what EXTRACT() does here:
http://php.net/manual/en/function.extract.php

Are you trying to display the results from the query?
Perhaps not echo $dag;
but, echo $row[‘dag’];

Also, there are date function to handle the conversion of numeric dates to string dates which would save some code for you… Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service