Cavemanharris
Cavemanharris

Reputation: 183

How to check Field is empty when displaying record

I want the PDF field to be hidden when the PDF Field is empty, I've search this forum and many others and the more I read the more I get confused !

I've marked the area in question with ==== before and after !

Here is my code:

<?php
$id = $_GET['id'];
if(empty($id))
    header('Location: news.php');
else
{
    mysql_connect('localhost','root','usbw');
    mysql_select_db('flexphpdir');
    $query = mysql_query("Select * From linkex WHERE linkexid = '$id'");
    if($query === false)
    {
        var_dump(mysql_error());
    }
    else
    {
        while($output = mysql_fetch_assoc($query))
        {
?>
            <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="320" height="184" data-setup="{}">
                <?php echo $output['title']; ?><br>
                <?php echo date('d-M-Y', $output['adddate']); ?><br>
                <?php echo $output['weekid']; ?>
                <source src="contentuploads/<?php echo $output['video']; ?>" type="video/mp4" />
            </video>
            //================================      
            <?php  if (get_field('pdf') != "")  { ?>
                //code if field has value ! = <?php echo $output['pdf']; ?> 
            <?php } else { ?>
                //code for no field value here
            <?php } ?>
            //=================================
<?php
        }
    }
?>
<?php } ?>

Upvotes: 0

Views: 182

Answers (2)

Prix
Prix

Reputation: 19528

One way would be using is_null to check the field:

if (is_null($output['pdf'])) 
{
    echo "No PDF";
}
else
{
    echo $output['pdf'];
}

if (is_null($output['pdf'])) can also be written as if ($output['pdf'] === NULL).

Here is a great question that even have a comparative chart of what it will give you as result.

Upvotes: 1

Angripa
Angripa

Reputation: 157

there are many ways to solve your problem, check php manual.. Here i code using isset() Try this

<?php
    if(isset($_POST['pdf'])){
       if($_POST['pdf'] == $output['pdf']){
           echo "<label></label>";
       }
    }
    else{
       echo "";//
    }
?>

Upvotes: 0

Related Questions