Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery在数据库值为NULL时隐藏HTML标记_Php_Jquery_Dreamweaver - Fatal编程技术网

Php jQuery在数据库值为NULL时隐藏HTML标记

Php jQuery在数据库值为NULL时隐藏HTML标记,php,jquery,dreamweaver,Php,Jquery,Dreamweaver,我正在使用Dreamweaver的内置PHP功能构建一个小应用程序。我在一个重复的ul,li结构中检索数据,如下所示 客户名称 职位描述 竣工年份 客户名称和职务说明将始终具有值,并且完成年份可能具有空值。如果完成年份的值为空,则不应显示“li” 我正试图用jQuery实现这一点,但对我来说似乎很复杂。我可以用PHP实现这一点吗 $array = array('client_name'=>'John', 'job_descr'=>'Programming', 'year'=>n

我正在使用Dreamweaver的内置PHP功能构建一个小应用程序。我在一个重复的ul,li结构中检索数据,如下所示

客户名称 职位描述 竣工年份 客户名称和职务说明将始终具有值,并且完成年份可能具有空值。如果完成年份的值为空,则不应显示“li”

我正试图用jQuery实现这一点,但对我来说似乎很复杂。我可以用PHP实现这一点吗

$array = array('client_name'=>'John', 'job_descr'=>'Programming', 'year'=>null);

foreach ($array as $data) {
    echo '<ul>';
    ($data['client_name']!=null)?echo '<li>'.$data['client_name'].'</li>':echo '';
    ($data['job_descr']!=null)?echo '<li>'.$data['job_descr'].'</li>':echo '';
    ($data['year']!=null)?echo '<li>'.$data['year'].'</li>':echo '';
    echo '<ul>';
}

如果我理解正确,这就是您需要的。

使用PHP将是合乎逻辑的方式-您必须向我们展示PHP源代码以帮助您做到这一点-它将只涉及If语句检查null,如果它是真的,则不回应该列表。。但是要回答你的jquery问题。。如果您的输出为:

<ul id="this_is_the_list">
    <li>
        <ul>
            <li>Client name value</li>
            <li>Job desc value</li>
            <li>This isnt null</li>
        </ul>
    </li>
    <li>
        <ul>
            <li>Another name value</li>
            <li>Another Job desc value - this one will be null</li>
            <li></li>
        </ul>
    </li>
</ul>​
您的jquery将是:

$(document).ready(function() {
        //for each additional list within the target list
        //which has a 3rd li (i would suggest giving this a
        //class instead to better target it).
        $('#this_is_the_list li li:nth-child(3)').each(function() {
            if($(this).text().length < 1) { //if its empty
                 $(this).parents('#this_is_the_list > li').remove(); //remove its parent list item
            }
        });
    });​

在此演示:

您可以向我们显示输出html吗?基本上是在php中检查是否为null,并且不打印创建该html的位置?您不需要将null值传递给客户端,然后将其隐藏在那里。您可以避免在php代码本身中使用null来回显li。