neki 0 Newbie Poster

I am creating a simple reservation calendar and have a mysql table 'reservation' with date_from and date_to fields. So, according to those dates I am taking red picture for booked, white for the first and last day and blue for not booked. And that is working well. The problem is if I have three reservations , the dates in my calendar look like this
111222333444 etc..I know that my loop isnt correct, but I've tried everything and can't seem to make it work. Please, help!

<table><tr>
<?php
$months = array("","sijecanj","veljaca","ozujak","travanj","svibanj","lipanj","srpanj","kolovoz","rujan","listopad","studeni","prosinac");


for($i=1;$i<=12;$i++){


$start_day = gmmktime(0,0,0,$i,1);



$start_day_number = date("w",$start_day);


$days_in_month = date("t",$start_day);?>


<td><?php echo $months[$i];?></td>


<?php
for($x=1;$x<=$days_in_month;$x++){
?><?php
$sql = "select * from reservations inner join stranica_title on reservations.id_item=stranica_title.id where id_item=3";


$result = mysql_query($sql) or print ("Can't select entries.<br />" . $sql . "<br />" . mysql_error());



while($row = mysql_fetch_array($result)) {
$naziv=$row;
$datum_od=date("Y-m-d", $row);
$datum_do=date("Y-m-d", $row);
$day_od=date("d", $row);
$day_do=date("d", $row);
$mjesec_od=date("m", $row);
$mjesec_do=date("m", $row);
$mjesec_od=ltrim($mjesec_od,0);
$mjesec_do=ltrim($mjesec_do,0);
$day_od=ltrim($day_od,0);
$day_do=ltrim($day_do,0);?>


<td>
<?php if(($x==$day_od || $x==$day_do) && $i==$mjesec_od){
?>
<img src="images/bijelo/bb<?php echo $x; ?>.gif">
<?php
}
if($x>$day_od && $x<$day_do && $i==$mjesec_od){
?>
<img src="images/crveno/cc<?php echo $x; ?>.gif">
<?php
}
if ($i<>$mjesec_od || $x<$day_od || $x>$day_do){?>
<img src="images/plavo/pp<?php echo $x; ?>.gif">
<?php
}} }
?></td></tr>
<?php
}
?>
</table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.