要隐藏的If/ifelse语句';h2';如果没有搜索结果


If / ifelse statement to hide 'h2' if no search results

如果没有搜索结果,有人能帮助我如何停止显示标题吗?

该应用程序基于flickr图像生成调色板,目前我有一些其他声明用于验证,如果没有来自flickr API等的结果,则会显示一条消息,如图所示:

      // 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>";
}

如果有结果,它将显示一个标题(#welcomeDiv),说明

正在显示的选项板。。。

然而,我只想在有结果的情况下显示这个,我已经尝试过:

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

我想要隐藏的welcomeDiv

<?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 } ?>

但这并不适用。有人知道为什么吗?

这是该项目的链接。

此编辑可以工作。

// 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>";
}

我看到链接中也提到了jquery。您可以使用javascript隐藏标题。

// 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>";
    }

基本上:

if ($has_results) {
   echo ...
} else {
   // do nothing
}

在相关部分进行if()测试,当你不想回声某个东西时,不要回声它。