duanhuren5581 2014-04-08 19:39
浏览 44
已采纳

如果没有搜索结果,如果/ if else语句隐藏'h2'

Can anybody help me on how I can stop an heading displaying if there are no search results?

The app generates palettes based on flickr images, at the minute I have a few else statements for validation that if there are no results from the flickr API etc, then a message will appear, as shown:

      // No results from Flickr
        } else {
            echo "<div class=\"errormsg\"> Uh oh... no results for that Hex. Why not try a keyword?</div>";
        }
    } else {
        // Error with the Flickr API
        echo "<div class=\"errormsg\"> Oh boy... there was an error with the API.</div>";
    }
} else {
    // No hex code entered
    echo "<div class=\"errormsg\"> Hey, it looks like you forgot to enter a hex code - Try again!</div>";
}

If there are results it will display a heading (#welcomeDiv) stating

Displaying palettes for...

However, I only want this to display if there are results, I have tried:

else{
?>
<style type="text/css">#welcomeDiv{
display:none;
}</style>
<?php
}

welcomeDiv that I want hidden

<?php if (isset($_POST['submit'])) { ?>
        <h2 id="welcomeDiv">Displaying palettes for <span class="hex">"<?php echo $_POST['hex'] ?>"</span></h2>

        <div id="results">
            <?php include 'assets/php/generate.php'; ?>
        </div><!--/results-->
    <?php } ?>

But this doesn't apply. Does anybody know why?

Here's a link to the project.

  • 写回答

2条回答 默认 最新

  • dpmir1988 2014-04-08 20:06
    关注

    This edit could work.

    // No results from Flickr
            } else {
    ?>
        <style type="text/css">#welcomeDiv{ display:none;}</style>
    <?php
                echo "<div class=\"errormsg\"> Uh oh... no results for that Hex. Why not try a keyword?</div>";
            }
        } else {
            // Error with the Flickr API
            echo "<div class=\"errormsg\"> Oh boy... there was an error with the API.</div>";
        }
    } else {
        // No hex code entered
        echo "<div class=\"errormsg\"> Hey, it looks like you forgot to enter a hex code - Try again!</div>";
    }
    

    I see you also have jquery referred in the link. You can use javascript to hide the heading.

    // No results from Flickr
                } else {
        ?>
            <script>$('#welcomeDiv').hide();</script>
        <?php
                    echo "<div class=\"errormsg\"> Uh oh... no results for that Hex. Why not try a keyword?</div>";
                }
            } else {
                // Error with the Flickr API
                echo "<div class=\"errormsg\"> Oh boy... there was an error with the API.</div>";
            }
        } else {
            // No hex code entered
            echo "<div class=\"errormsg\"> Hey, it looks like you forgot to enter a hex code - Try again!</div>";
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗