当没有内容时隐藏2个DIV

时间:2022-09-25 18:00:44

I have a slideshow with thumbnails associated with each slide. So I have 10 DIV's that represent slides like this...

我有一个幻灯片,每个幻灯片都有缩略图。所以我有10个DIV代表这样的幻灯片......

<div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image -->

        <?php
        while ($row = mysql_fetch_array($query)) {
        echo "<img class='img' src={$row['img']} width='350px' height='225px'>";
        }
        ?>              

 </div>

And 10 other DIV's that represent the thumbnails

还有10个代表缩略图的DIV

    <div class="SSSlide thumbnail" id="u780"><!-- associated div -->
I am a thumbnail linked to a slide
</div>

When the query within each slide DIV has no results returned (no contents within), I would like to remove that DIV and it's associated thumbnail DIV. I'd like this to happen when page opens so whatever slides are emtpy, the slide itself and it's thumb DIV will be removed completely (not just hidden)

当每个幻灯片DIV中的查询没有返回结果(没有内容)时,我想删除该DIV及其关联的缩略图DIV。我希望在页面打开时发生这种情况,因此无论幻灯片是什么幻灯片,幻灯片本身和它的拇指DIV都将被完全删除(不仅仅是隐藏)

I've looked around google and such, but nothing seems to work. Thanks in advance for any assistance.

我环顾谷歌等等,但似乎没什么用。在此先感谢您的任何帮助。

1 个解决方案

#1


You have to store the thumbnail content into database as well.

您还必须将缩略图内容存储到数据库中。

First method - Select Query

第一种方法 - 选择查询

You can directly deselect the empty content rows. For example:

您可以直接取消选择空内容行。例如:

$sql = "select * from image_tbl" where (your condition) and img != ''";

Second method - If Clause

第二种方法 - 如果条款

<div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image -->
    <?php
    while ($row = mysql_fetch_array($query)) {
         if($row['img'] != ""){
            echo "<img class='img' src={$row['img']} width='350px' height='225px'>";
        }
    }
    ?>   
</div>

Here I'm assuming you storing img and thumbnail in database:

在这里,我假设您将img和缩略图存储在数据库中:

<div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image -->

    <?php
    while ($row = mysql_fetch_array($query)) {
        echo "<img class='img' src={$row['img']} width='350px' height='225px'>";
        $thumbnail_str .= "
            <div class='SSSlide thumbnail' id='u780'><!-- associated div -->
                $row[thumbnail]
            </div>
        ";
    }
    ?>              

</div>
echo $thumbnail_str;

Hope these helps! :)

希望这些有帮助! :)

#1


You have to store the thumbnail content into database as well.

您还必须将缩略图内容存储到数据库中。

First method - Select Query

第一种方法 - 选择查询

You can directly deselect the empty content rows. For example:

您可以直接取消选择空内容行。例如:

$sql = "select * from image_tbl" where (your condition) and img != ''";

Second method - If Clause

第二种方法 - 如果条款

<div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image -->
    <?php
    while ($row = mysql_fetch_array($query)) {
         if($row['img'] != ""){
            echo "<img class='img' src={$row['img']} width='350px' height='225px'>";
        }
    }
    ?>   
</div>

Here I'm assuming you storing img and thumbnail in database:

在这里,我假设您将img和缩略图存储在数据库中:

<div class="SSSlide clip_frame grpelem slide" id="u751"><!-- image -->

    <?php
    while ($row = mysql_fetch_array($query)) {
        echo "<img class='img' src={$row['img']} width='350px' height='225px'>";
        $thumbnail_str .= "
            <div class='SSSlide thumbnail' id='u780'><!-- associated div -->
                $row[thumbnail]
            </div>
        ";
    }
    ?>              

</div>
echo $thumbnail_str;

Hope these helps! :)

希望这些有帮助! :)