php - How to put information dynamically on tables using jQuery based on certain criteria? -
let's imagine have make table following structure php. every cell identified namedayhour indicator ( mon0, mon1, , on every day ). should put information on cells, different every day , hour.
the whole structure :
<table border="1" > <th>hour</th> <th>mon 25-06-2012</th> <th>tue 26-06-2012</th> <th>wed 27-06-2012</th> <th>thu 28-06-2012</th> <th>fri 29-06-2012</th> <tr><td>8:00</td><td>mon0</td><td>tue0</td><td>wed0</td><td>thu0</td><td>fri0</tr> <tr><td>8:20</td><td>mon1</td><td>tue1</td><td>wed1</td><td>thu1</td><td>fri1</tr> <tr><td>8:40</td><td>mon2</td><td>tue2</td><td>wed2</td><td>thu2</td><td>fri2</tr> <tr><td>9:00</td><td>mon3</td><td>tue3</td><td>wed3</td><td>thu3</td><td>fri3</tr> <tr><td>9:20</td><td>mon4</td><td>tue4</td><td>wed4</td><td>thu4</td><td>fri4</tr> <tr><td>9:40</td><td>mon5</td><td>tue5</td><td>wed5</td><td>thu5</td><td>fri5</tr> </table> so, have arrays:
$hoursmonday = array("8:00", "8:20", "8:40") $hoursmondayassigned = array("8:00", "8:20") $hoursmondayavailable = array("8:40") i have these 3 arrays every day monday friday.
then need write hours in table every day. example, in case, need put on cell monday , hour: 8:40 text "available", , "8:00" , "8:20" should put on column monday these hours, system should put "busy" both of them.
the resulting table, using arrays of example, should following table:
<table border="1" > <th>hour</th> <th>mon 25-06-2012</th> <th>tue 26-06-2012</th> <th>wed 27-06-2012</th> <th>thu 28-06-2012</th> <th>fri 29-06-2012</th> <tr><td>8:00</td><td>busy</td><td>tue0</td><td>wed0</td><td>thu0</td><td>fri0</tr> <tr><td>8:20</td><td>busy</td><td>tue1</td><td>wed1</td><td>thu1</td><td>fri1</tr> <tr><td>8:40</td><td>available</td><td>tue2</td><td>wed2</td><td>thu2</td><td>fri2</tr> <tr><td>9:00</td><td>mon3</td><td>tue3</td><td>wed3</td><td>thu3</td><td>fri3</tr> <tr><td>9:20</td><td>mon4</td><td>tue4</td><td>wed4</td><td>thu4</td><td>fri4</tr> <tr><td>9:40</td><td>mon5</td><td>tue5</td><td>wed5</td><td>thu5</td><td>fri5</tr> </table> </html> i use jquery, or php solve this.
one of things note, parameter of frequency ( in case 10 minutes ) might vary. if frequency set 30 minutes, example, times be: 8:00 , 8:30, 9:00, 9:30 , on.
i don't know how solve using jquery. know how write table using loop, complexity leveling when need put information on correct cell depending of day , hour.
thanks.
you following in php find out each hour if it's assigned or free:
$hoursmonday = array("8:00", "8:20", "8:40"); $hoursmondayassigned = array("8:00", "8:20"); $hoursmondayavailable = array("8:40"); foreach( $hoursmonday $hour ) { if( in_array( $hour, $hoursmondayassigned ) ) { echo 'busy @ ' . $hour; } else if ( in_array( $hour, $hoursmondayavailable ) ) { echo 'free @ ' . $hour; } } to automate looping through days suggest using recursive array each day, example:
$monday = array( 'free' => array( '08:40', '09:00' ), 'busy' => array( '08:40', ), 'free' => array( '09:00', ), );
Comments
Post a Comment