简体   繁体   English

如何根据某些条件使用jQuery动态将信息放在表上?

[英]How to put information dynamically on tables using jQuery based on certain criteria?

Let's imagine that I have to make a table with the following structure with PHP. 让我们想象一下,我必须使用PHP创建具有以下结构的表。 Every cell identified with NamedayHour is just an indicator ( Mon0, Mon1, and so on for every day ). NamedayHour标识的每个单元格都只是一个指示器(每天的Mon0,Mon1,依此类推)。 I should put information on that cells, that is different for every day and hour. 我应该在该单元格上放置信息,这在每天和每个小时都是不同的。

The whole structure is something like this : 整个结构是这样的:

<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, I have the arrays: 所以,我有数组:

$hoursMonday = array("8:00", "8:20", "8:40")
$hoursMondayAssigned = array("8:00", "8:20")
$hoursMondayAvailable = array("8:40")

I have these 3 arrays for every day from Monday to Friday. 从星期一到星期五,我每天都有这3个数组。

Then I need to write the hours in the table for every day. 然后,我需要将每天的小时数写在表中。 For example, in this case, I need to put on the cell for Monday and hour: 8:40 the text "Available", and for "8:00" and "8:20" I should put on the column Monday for these hours, the system should put "Busy" for both of them. 例如,在这种情况下,我需要将星期一和小时的单元格放在:8:40的文本“ Available”,对于“ 8:00”和“ 8:20”,我应该在星期一的栏上输入小时,系统应为他们两个都设置“忙碌”。

The resulting table, using the arrays of the example, should be like the 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 would like to use jQuery, or just PHP to solve this. 我想使用jQuery或仅使用PHP来解决此问题。

One of the things to note, is that the parameter of frequency ( in this case 10 minutes ) might vary. 要注意的事情之一是频率参数(在本例中为10分钟)可能会有所不同。 If the frequency is set to 30 minutes, for example, the times will be: 8:00 , 8:30, 9:00, 9:30 and so on. 例如,如果将频率设置为30分钟,则时间将为:8:00、8:30、9:00、9:30,依此类推。

I don't really know how to solve this using jQuery. 我真的不知道如何使用jQuery解决此问题。 I know how to write the table using a for loop, but complexity is leveling up when I need to put the information on the correct cell depending of the day and hour. 我知道如何使用for循环编写表,但是当我需要根据日期和时间将信息放置在正确的单元格上时,复杂性正在提高。

Thanks. 谢谢。

You could do the following in PHP to find out for each hour if it's assigned already or free: 您可以在PHP中执行以下操作,以了解每小时是否已分配或免费分配:

$hoursMonday = array("8:00", "8:20", "8:40");
$hoursMondayAssigned = array("8:00", "8:20");
$hoursMondayAvailable = array("8:40");

foreach( $hoursMonday AS $hour ) {
    if( in_array( $hour, $hoursMondayAssigned ) ) {
        echo 'Busy at ' . $hour;
    } else if ( in_array( $hour, $hoursMondayAvailable ) ) {
        echo 'Free at ' . $hour;
    }
}

To automate looping through all the days I would suggest using a recursive array for each day, for example: 为了自动遍历整天,我建议每天使用递归数组,例如:

$monday = array(
    'free' => array(
        '08:40', '09:00'
    ),

    'busy' => array(
        '08:40',
    ),

    'free' => array(
        '09:00',
    ),
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL-如何根据某些条件从两个表中检索字段? - Mysql - How to retrieve fields from two tables based on certain criteria? 基于动态生成信息的jQuery UI对话框 - jQuery UI dialogs based on dynamically generated information 如何根据某些条件使用mysql详细信息发送大量电子邮件? - How do you send mass emails using mysql details based on certain criteria? 如何使用jQuery和PHP动态显示更多信息? - How to dynamically show further information with jQuery and PHP? 使用jQuery Dialog基于表动态显示信息 - Use jQuery Dialog to dynamically show information based on a table 如何在DataTable jQuery插件中放置多个表 - How to put multiple tables in the DataTable jQuery plugin 如何使用 Apache Tomcat 服务器根据用户登录信息动态更改 html 文件? - How to change html files dynamically based on user login information using Apache Tomcat Server? 如何使2个表中的信息基于记录值进行匹配 - How to make information from 2 tables match based on record value 如何使用表的ID从数据库中检索某些信息以提取某些信息? - How do I retrieve certain information from database using the ID of the table to extract certain information? 如何使用jQuery或任何其他方法根据浏览器窗口的宽度动态加载不同的php文件 - how to load a diferrent php file dynamically based on the browser window's width using jQuery or any other method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM