1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    A condition to hide a section of the details page


    I have a section (THEFT) of a details page which I do not want to be visible if none of the three variables have data in them. This section starts with a h3 tag followed by a div class within which are the three variables:

    PHP Code:
    <h3 onClick="expandcontent('sc2')" style="cursor:hand; cursor:pointer">THEFT</h3>
    <div id="sc2" class="switchcontent">
        <td>Theft Date</td>
        <td colspan="3" bgcolor="#eeeeee"><?php echo $theftDate?></td>
        <td>INTERPOL Ref.</td>
        <td colspan="3" bgcolor="#eeeeee"><?php echo $interpol_ref?></td>
        <td colspan="3" bgcolor="#eeeeee"><?php echo $facts?></td>
    How can I create a condition that will hide this section when all the three variables are unpopulated?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    if the variables may not even be defined, use empty(). Otherwise, simply make a boolean check of the variables:

    PHP Code:
    <?php if ($theftDate && $interpol_ref && $facts): ?>
        <!-- your HTML -->
    <?php endif; ?>
    By the way, avoid mixing different naming styles (under_score and camelCase).

    Comments on this post

    • josephbupe agrees : Thank you so much. It works fine.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo