Jump to content
php.lv forumi

iekrasot dienas


destroy_all

Recommended Posts

Nē... es darītu tā..

 

foreach/while ( $room = $query->get() )
{
print '<tr>'; 
$activities = array();
while ($activity)
{
   $activities[$activity->diena] = $activity->diena;
}

for ($diena=DienaNo;$diena<=DienaLidz;$diena++)
{
	print "<td class="'.(empty($activities[$diena])?'free':'used').'" ... > ... ";
}
print '</tr>'; 
}

Edited by Delfins
Link to comment
Share on other sites

$days=array_fill(0,31,'green'); //uztaisam array ar vajadziigo dienu skaitu

 

 

for($i=$day_from;$i<=$day_to;$i++) $days[$i]='pink'; //ieziimejam arraya aiznjemtas dienas

 

echo '<tr>';

foreach ($days as $day) echo "<td class=\"$day"\ ></td>"; /izvadam attieciigo array, kaa vien veelamies

echo '</tr>';

Link to comment
Share on other sites

bubu, a iedomaajies N periodus

$activities tiek inizializēts no datubazes...

 

ACT:_E_E_F_F_F_E_E_E_E_F_
DAY:_D_D_D_D_D_D_D_D_D_D_
HTM:_0_0_1_1_1_0_0_0_0_1_

 

pseidokods

while ($activities_row)
{
 // add to array
}

for (diena = [diena_from .. diena_to])
{
  stils = (empty(activity[diena])) ? "FREE" : "USED";
  print "<td STILS>DIENA</td>"
}

Edited by Delfins
Link to comment
Share on other sites

IMHO, tam tā vajadzētu izskatīties. Testējis gan neesmu, tak pēc loģikas, vajadzētu iet :)

<?php

$days_this_month = 31; // te dabunam konkreta menesa dienu skaitu

$query = "SELECT room_id FROM rooms";
$res = mysql_query($query);
?>
<table>
<?
while($row = mysql_fetch_array($res)) {
$occupied = get_occupied_dates($row['room_id']);  

echo '<tr>';

for($i = 1; $i <= $days_this_month; $i++) {
	$class = in_array($i,$occupied)? 'occupied' : 'free';

	echo '<td class="'.$class.'">'.$i.'</td>';
}
echo '</tr>';	  
}
?>
</table>
<?
function get_occupied_dates($room_id) {
$occupied = array();
$query = "SELECT DAY(oc_from) as oc_from, DAY(oc_to) as oc_to FROM activity WHERE room_id=$room_id";
$res = mysql_query($query);
while($row = mysql_fetch_array($res)) {
	$occ = range($row['oc_from'],$row['oc_to']);
	$occupied = array_merge($occupied,$occ);
}
return $occupied;
}
?>

Link to comment
Share on other sites

×
×
  • Create New...