English 中文(简体)
PHP foreach and while loop to ordertimelot
原标题:PHP foreach and while loop to order timeslots

After a little help here. I m looking to produce some code that will take an incoming array of data, and order the data by time (This I can do easily enough)

我的议席上有22个时段,因此,我需要各行各占22个(阵列中每个项目都具有块状价值),我可以这样做。

我接着正在拿到这种数据阵列,并说,如果从09:00am到3个位置,则需要3个位置(我可以做的),但如果09:00am是当天的第一个项目,则需要先设定1个区块位置,直到它发现阵列中的第1个位置,那么下一个排位数为14个。

i.e. 相反

test1, 2slots, 09:00, room1
test1, 1slot, 12:00, room1 
test1, 2slots, 13:00, room1
test1, 4slots, 15:00, room1
10
11
12
13
...
22

我谨表示,

1
2
3
4
test1, 2slots, 09:00, room1, 6
7
8
9
10
test1, 1slot, 12:00, room1, 11
12
test1, 2slots, 13:00, room1, 14
15
16
test1, 4slots, 15:00, room1, 20
21
22

我的职能目前是(这归第一编)。

if(is_array($meetrooms)){
$i = 0;
foreach($meetrooms as $valuer){ 
    $b = $valuer[ num_blocks ];
    $i += $b;
    ?>
    <span><?php echo $valuer[ title ] . " " . $valuer[ num_blocks ] . " " . $valuer[ room_name ]  . " " . $i . " " . br() ;?></span>
<?php       
}
if($i != 22){ 
    while($i <= 22){ ?>
        <span><?php echo $i . br() ;?></span>
<?php
        $i++;
    }
}
}

我的阵列已经减少,但结构已经结构化。

[0] => Array
    (
        [mr_id] => 3
        [title] => test1 meeting
        [description] => Some meeting going on here
        [staff_id] => 2454
        [room_name] => room1
        [start_date] => 2012-04-20 00:43:58
        [start_time] => 08:00:00
        [end_date] => 2012-04-20 00:43:58
        [end_time] => 09:00:00
        [num_blocks] => 2
    )

Any help would be fantastic!!! Need anything else please ask

www.un.org/spanish/ga/president

I m 90%

只有问题才是问题。 如何在休息时间外加固价值?

if(is_array($meetingrooms))
{
$time = date( H:i , strtotime("07:00"));
$i = 1;
foreach($meetingrooms as $valuer)
{ 
    while ($time < $valuer[ start_time ])
    { ?>
        <span><?php echo "....." . $time . " " . $i . ".....";?></span>
    <?php
        $prev = date( H:i , strtotime($time));
        $next = strtotime( +30mins , strtotime($prev));
        $time = date( H:i , $next);
        $i++;
    }
    $nummins = $valuer[ num_blocks ] * 30 - 30;
    $next = strtotime( +  . $nummins .  mins , strtotime($time));
    $time = date( H:i , $next);
    $b = $valuer[ num_blocks ];
    echo  "td" . $valuer[ num_blocks ];
    $i = $i + 1;
}
$timetofinish = date( H:i , strtotime("18:00"));
if ($time < $timetofinish)
{
    while ($time < $timetofinish)
    {
        echo "<span>......$time..." . $i  . "</span>";
        $prev = date( H:i , strtotime($time));
        $next = strtotime( +30mins , strtotime($prev));
        $time = date( H:i , $next); 
        $i++;
    }
}
}

What it now returns is

.....07:00 1..... .....07:30 2..... .....08:00 3..... td2    .....09:00 5..... .....09:30 6..... .....10:00 7..... .....10:30 8..... td1     .....11:00 10..... .....11:30 11..... .....12:00 12..... td4    .....14:00 14..... .....14:30 15..... .....15:00 16..... td1......15:30...18......16:00...19......16:30...20......17:00...21......17:30...22
问题回答

你们是否试图设定某种教室保留时间?

date_default_timezone_set (  GMT  );
$meetingrooms = array ( /* ... YOUR DATA ... */ );

define ( MAX_SLOTS , 22);
define ( START_TIME , strtotime( 05:00 ));
define ( END_TIME , strtotime( 22:00 ));
$rooms = array ( "room1", "room2" );
$reserved = array();
foreach ($rooms as $room) {
    $reserved[$room] = array();
    for($t = START_TIME; $t <= END_TIME; $t = strtotime( +30mins , $t)) {
        $reserved[$room][$t] = "FREE";
    }
}

foreach ($meetingrooms as $valuer) {
   $t = strtotime($valuer[ start_time ]);
   while ( $t < strtotime($valuer[ end_time ])) {
       $reserved[$valuer[ room_name ]][$t] = $valuer;
       $t += strtotime( +30mins , $t);
   }      
}

foreach ($reserved as $roomname=>$reservations) {
    echo "{$roomname}: ";
    foreach ($reservations as $t=>$valuer) {
        echo date("H:i", $t).( ($valuer === "FREE") ? "...." : $valuer[ title ])." | ";
    }
    echo "
";
}

现在,你可以修改产出(超文本/XML/帽子),以满足你们的要求。

核对这一样本代码。

    <?php 
        //Sample time loop.
        $time = new DateTime( 2011-11-17 08:00:00 );
        $end = new DateTime( 2011-11-17 20:00:00 );

        while ($time < $end) {

            echo $stamp = $time->format( h:i a ) .  </br> ;
            $time->add(new DateInterval( PT  . 30 .  M ));
        }
    ?>

资源: 每次和休息时间:





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签