简体   繁体   English

在日历中添加活动

[英]Add an event in a calendar

I solved a few months ago the problem of getting data from two tables and make an event calendar. 几个月前,我解决了从两个表中获取数据并制作事件日历的问题。 You can see here: original question . 您可以在此处看到: 原始问题 Now I want something more: I want to ad an event for EVERY users in the same time. 现在,我需要更多:我想同时为每个用户播送一个活动。 Let's say is a holiday (like Christmas) and I want to add this event for all users. 假设是一个假期(例如圣诞节),我想为所有用户添加此活动。 I am using two queries first is to select the holidays and second to select if user was present. 我正在使用两个查询,第一个是选择假期,第二个选择是否存在用户。 If present tip_id = 0, if not tip_id = 1. Than I put everything in a table. 如果存在tip_id = 0,则不存在tip_id = 1。 If the day is Saturday or Sunday the color is grey (using css1), if user is present the cell color is white and if user is absent the color is red. 如果日期是星期六或星期日,则颜色为灰色(使用css1),如果用户在场,则单元格颜色为白色,如果用户不在,则颜色为红色。 What I need? 我需要的? If I have Holidays in that month, I need the cell color to be also grey (as Saturday and Sunday). 如果该月有假期,则我需要将单元格颜色也设置为灰色(如星期六和星期日)。 I tried different ideas but or I was able to get grey ONLY the first Holiday day, or ONLY the last or I got error when there are NO holidays in that month. 我尝试了不同的想法,但是或者只有在第一个假日那天才能够显示灰色,或者只有最后一个假日才能够显示灰色,或者当该月没有假日时我会出错。 The code (extracted only the part where I need help) is like this: 代码(仅提取需要帮助的部分)如下所示:

$db_luna=11;
$db_an=2013;
$days_in_month = 31;

mysql_select_db($database_dbconfig, $dbconfig);
$query_Holidays = "SELECT substring(data,9,2) AS zile_sarbatoare, data FROM sarbatori WHERE sarbatori.`data` LIKE '".$db_an."-".$db_luna."-%' ORDER BY zile_sarbatoare";
$Holidays = mysql_query($query_Holidays, $dbconfig) or die(mysql_error());
$row_Holidays = mysql_fetch_assoc($Holidays);
$totalRows_Holidays = mysql_num_rows($Holidays);

mysql_select_db($database_dbconfig, $dbconfig);
$query_Presence = "SELECT c.full_name, c.id_personal, COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-01') BETWEEN start_date AND end_date THEN tip_id END),0) '1', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-02') BETWEEN start_date AND end_date THEN tip_id END),0) '2', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-03') BETWEEN start_date AND end_date THEN tip_id END),0) '3', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-04') BETWEEN start_date AND end_date THEN tip_id END),0) '4', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-05') BETWEEN start_date AND end_date THEN tip_id END),0) '5' FROM calendar c";
$Presence = mysql_query($query_Presence, $dbconfig) or die(mysql_error());
$row_Presence = mysql_fetch_assoc($Presence);
$totalRows_Presence = mysql_num_rows($Presence);}



<?php do { ?>
        <tr>
            <td><?php echo $nr_crt, '. ' , $row_Presence['full_name']; ?></td>
                <?php           
                $css1 = 'white';
                $trim = ''; 
                    for ($a = 1; $a <= $days_in_month; $a++){
                        $data_calculata = date("Y-m-d",mktime(0,0,0, $db_luna, $b, $db_an ));
                            if ($row_Presence[$a] == 0) {$legend = $row_Presence['full_name']."".$a;
                                                         $day_of_week = date("N",mktime(0,0,0, $db_luna,$a ,$db_an));
                                                         if ($day_of_week == 6 OR $day_of_week == 7) {$css1 = 'grey';}
                                                         else {$css1 = 'white';}
                            if ($row_Presence[$a] == 1) {$css1 = 'red'; $legend = $row_Presence['full_name']." - Absent";}
                        echo '<td " title= "'.htmlspecialchars($legend).'" class='.$css1.'></td>';
                        $nr_crt = $nr_crt + 1;
                ?>          
        </tr>            
    <?php } while ($row_Presence = mysql_fetch_assoc($Presence)); ?>
  </table>

The solution I found is like this: 我找到的解决方案是这样的:

$db_luna=11;
$db_an=2013;
$days_in_month = 31;

mysql_select_db($database_dbconfig, $dbconfig);
$query_Holidays = "SELECT substring(data,9,2) AS zile_sarbatoare, data FROM sarbatori WHERE sarbatori.`data` LIKE '".$db_an."-".$db_luna."-%' ORDER BY zile_sarbatoare";
$Holidays = mysql_query($query_Holidays, $dbconfig) or die(mysql_error());
$totalRows_Holidays = mysql_num_rows($Holidays);
$days_holidays = array();
while ($row_Holidays = mysql_fetch_array($Holidays))
 {
     $days_holidays[] = $row_Holidays['zile_sarbatoare'];
 }
// so, now I have an array with all the days I need

mysql_select_db($database_dbconfig, $dbconfig);
$query_Presence = "SELECT c.full_name, c.id_personal, COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-01') BETWEEN start_date AND end_date THEN tip_id END),0) '1', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-02') BETWEEN start_date AND end_date THEN tip_id END),0) '2', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-03') BETWEEN start_date AND end_date THEN tip_id END),0) '3', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-04') BETWEEN start_date AND end_date THEN tip_id END),0) '4', COALESCE(MIN(CASE WHEN CONCAT($db_an, '-', $db_luna, '-05') BETWEEN start_date AND end_date THEN tip_id END),0) '5' FROM calendar c";
$Presence = mysql_query($query_Presence, $dbconfig) or die(mysql_error());
$row_Presence = mysql_fetch_assoc($Presence);
$totalRows_Presence = mysql_num_rows($Presence);}



<?php do { ?>
    <tr>
        <td><?php echo $nr_crt, '. ' , $row_Presence['full_name']; ?></td>
            <?php           
            $css1 = 'white';
            $trim = ''; 
                for ($a = 1; $a <= $days_in_month; $a++){
                    $data_calculata = date("Y-m-d",mktime(0,0,0, $db_luna, $b, $db_an ));
                     if ($row_Presence[$a] == 0) {$legend = $row_Presence['full_name']."".$a;
                                                     $day_of_week = date("N",mktime(0,0,0, $db_luna,$a ,$db_an));
                           $css1 = 'white';                                                         
                        if ($day_of_week == 6 OR $day_of_week == 7) {$css1 = 'grey';}
                        if (in_array($a, $days_holidays)) {$css1 = 'grey';} //here I compare each day if it is in the array
                     if ($row_Presence[$a] == 1) {$css1 = 'red'; $legend = $row_Presence['full_name']." - Absent";}
                    echo '<td " title= "'.htmlspecialchars($legend).'" class='.$css1.'></td>';
                    $nr_crt = $nr_crt + 1;
            ?>          
    </tr>            
<?php } while ($row_Presence = mysql_fetch_assoc($Presence)); ?>

For me it is working! 对我来说,它正在工作! The idea to use function "in_array" come from another question from this site. 使用函数“ in_array”的想法来自该站点的另一个问题。 Thank you stackoverflow :) 谢谢stackoverflow :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM