如果没有第1行

时间:2016-02-27 21:26:48

标签: php jquery html if-statement conditional

我正在开展一个让我感到沮丧的项目,因为我觉得我可能对条件逻辑感到满意。该网站为eqcalendar.com,属于私人实体。

我的目标是使这个用户友好,以便该组中的任何人都可以访问.txt文件,编辑变量,并且它们会正确显示。

我试图说明如果一个变量留空,没有任何字符出现,但如果变量被填充,它们就会显示出来。

我希望每周重复一次,为期三个月。当我完成第1天时,我进入第2天但第2天将无法工作,除非所有变量都在第1天定义。

如果没有填写日期,我也可以关掉这一天,它会添加一个css内联显示:none;。它工作但现在不会。我发现我添加的if语句越多,似乎就越少合作。

我注意到了jQuery切换的相同之处。我添加的越多,那么没有其他月份可以使用。

这应该是一个简单的移动设备网络应用程序。我有以下要素:

在DOCTYPE之上,我在.txt文件中有PHP调用

<?php
$title = "EQ Calendar";
include 'planner.txt'; ?>

planner.txt文件如下所示:

/*** MONTH 1 ***/
$month1 = "February";

    /** WEEK 1 **/
        $m1w1_Day               =   "07";
        $m1w1_Chapter           =   "4";
        $m1w1_Chapter_Header    =   "Test";
        $m1w1_Chapter_Link      =   "Testing";
        $m1w1_Conf_Header       =   "Tester";
        $m1w1_Conf_Speaker      =   "Dieter";
        $m1w1_Conf_Link         =   "http://www.google.com";
        $m1w1_Teacher           =   "Steven Scott";
        $m1w1_Other             =   "Presidency Message";

    /** WEEK 2 **/
        $m1w2_Day               =   "14";
        $m1w2_Chapter           =   "";
        $m1w2_Chapter_Header    =   "";
        $m1w2_Chapter_Link      =   "";
        $m1w2_Teacher           =   "";
        $m1w2_Other             =   "Stake Conference";

    /** WEEK 3 **/
        $m1w3_Day               =   "21";
        $m1w3_Chapter           =   "2";
        $m1w3_Chapter_Header    =   "My Peace I Give unto You";
        $m1w3_Chapter_Link      =   "";
        $m1w3_Teacher           =   "Joshua Hayes";
        $m1w3_Other             =   "";

    /** WEEK 4 **/
        $m1w4_Day               =   "28";
        $m1w4_Chapter           =   "";
        $m1w4_Chapter_Header    =   "";
        $m1w4_Chapter_Link      =   "";
        $m1w4_Conf_Header       =   "Be Not Afraid, Only Believe by Dieter F. Uchtdorf";
        $m1w4_Conf_Speaker      =   "Dieter F. Uchtdorf";
        $m1w4_Conf_Link         =   "";
        $m1w4_Teacher           =   "Jory Wahlen";
        $m1w4_Other             =   "";

    /** WEEK 5 **/
        $m1w5_Day               =   "";
        $m1w5_Chapter           =   "";
        $m1w5_Chapter_Header    =   "";
        $m1w5_Chapter_Link      =   "";
        $m1w5_Conf_Header       =   "";
        $m1w5_Conf_Speaker      =   "";
        $m1w5_Conf_Link         =   "";
        $m1w5_Teacher           =   "";
        $m1w5_Other             =   "";

index.php中的PHP代码如下:

<div class="top-header">
                <h1><?php echo $month1 ?> <span><i class="fa fa-close month1"></i></span></h1>
            </div>
            <div class="col-md-2 col-sm-2"></div>
            <div class="col-md-8 col-sm-8">
                <p <?php if (empty($m1w1_Day)) { echo "style='display:none;'"; } ?>><strong><?php echo $m1w1_Day ?></strong> <i class="fa fa-ellipsis-v"></i>
                <?php
                    if ($m1w1_Chapter !== "") {
                        if (empty($m1w1_Chapter)) {
                            return null;
                        } else {
                            echo "Ch. $m1w1_Chapter &ndash;";
                        }
                        if (empty($m1w1_Chapter_Header)) {
                            return null;
                        } elseif ($m1w1_Chapter_Link == "") {
                            echo " $m1w1_Chapter_Header";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                        } else {
                            echo " <a href='$m1w1_Chapter_Link'>$m1w1_Chapter_Header</a>";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                        }
                    } elseif ($m1w1_Conf_Header !== "") {
                        if (empty($m1w1_Conf_Header)) {
                            return null;
                        } elseif ($m1w1_Conf_Link == "") {
                            echo " $m1w1_Conf_Header";
                        } else {
                            echo " <a href='$m1w1_Conf_Link'>$m1w1_Conf_Header</a>";
                        }
                        if (empty($m1w1_Conf_Speaker)) {
                            return null;
                        } else {
                            echo " by $m1w1_Conf_Speaker";
                            if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; } 
                        }
                    } else {
                        echo "$m1w1_Other";
                        if (empty($m1w1_Teacher)) { return null; } else { echo " &ndash; $m1w1_Teacher"; }
                    }
                ?></p>
            </div>

我的目标是能够每周和每月重复此代码。我是否遗漏了任何妨碍我将if条件隔离到干扰其他ifs的单个变量的元素?

0 个答案:

没有答案