destroy_all Posted August 24, 2006 Author Report Share Posted August 24, 2006 foreach nočakarē visu tabulas struktūru. ok, pamēģināsu šito variantu. Link to comment Share on other sites More sharing options...
bubu Posted August 24, 2006 Report Share Posted August 24, 2006 foreach nočakarē visu tabulas struktūru. wtf? foreach neko nečakarē, ja vien pats tu nemaini datus. Tikpat labi arī while/for/if "čakarē visu tabulas struktūru" (lai ko arī tas nozīmētu). Link to comment Share on other sites More sharing options...
destroy_all Posted August 24, 2006 Author Report Share Posted August 24, 2006 (edited) jā, nenocakarē gan. http://paste.php.lv/4334 - atkal tā pati problēma. Edited August 24, 2006 by destroy_all Link to comment Share on other sites More sharing options...
bubu Posted August 24, 2006 Report Share Posted August 24, 2006 Dumāku for/if kombināciju sen nebiju redzējis. Dzēs visu ārā, un sāc zīmēt blokshēmas. Citādi palīdzēt vairs nevaru. Link to comment Share on other sites More sharing options...
Kristabs Posted August 24, 2006 Report Share Posted August 24, 2006 es dariitu taa: select visas vajadziigaas dienas { $from_till[$sql['no']] = $sql['lidz']; } for(){ //ziimeejam to datu tabulu foreach($from_till as $no => $liidz){ if($cur_day >= $no || $cur_day <= $liidz){ //iekraasojam } } } Link to comment Share on other sites More sharing options...
Delfins Posted August 25, 2006 Report Share Posted August 25, 2006 (edited) 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 August 25, 2006 by Delfins Link to comment Share on other sites More sharing options...
Gundars Posted August 25, 2006 Report Share Posted August 25, 2006 $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 More sharing options...
bubu Posted August 25, 2006 Report Share Posted August 25, 2006 Delfin: kāda jēga inicializēt masīvu $activities ciklā, ja tas ir invariants pret to? Link to comment Share on other sites More sharing options...
Delfins Posted August 25, 2006 Report Share Posted August 25, 2006 (edited) 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 August 25, 2006 by Delfins Link to comment Share on other sites More sharing options...
john.brown Posted August 25, 2006 Report Share Posted August 25, 2006 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 More sharing options...
destroy_all Posted August 25, 2006 Author Report Share Posted August 25, 2006 john.brown, paldies, viss strādā! Link to comment Share on other sites More sharing options...
Recommended Posts