0

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 } ?>
Prix
  • 19,417
  • 15
  • 73
  • 132
Cavemanharris
  • 185
  • 2
  • 14
  • [Welcome to stackoverflow, **please take your time to make a tour here and see how to best use stackoverflow**](http://stackoverflow.com/about) – Prix Jun 29 '13 at 08:42

2 Answers2

1

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.

Community
  • 1
  • 1
Prix
  • 19,417
  • 15
  • 73
  • 132
  • @Cavemanharris what is your PDF field a text ? a number ? is it NULL when empty or is it a string with no text when empty ? – Prix Jun 28 '13 at 23:32
  • yes it is a text string with no text...! i made it test because all it stores is the file name of the pdf!.. again.. my knowledge of PHP is terrible ! i used to play with ASP years ago and then doing it with asp and access it worked. but starting to look around at PHP i see there are more than many ways to do a thing and the rules are just to complicated for comfort. – Cavemanharris Jun 28 '13 at 23:42
  • @Cavemanharris then yes **`is_null`** should work just fine, see this answer that I quoted above **http://stackoverflow.com/a/15607549/342740**, there is chart of what the result will come out in different cases, in your case, you can use **`if (is_null($output['pdf']))`** or **`if ($output['pdf'] === NULL)`** and they should both return false meaning there is no data. – Prix Jun 28 '13 at 23:45
0

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 "";//
    }
?>
Angripa
  • 159
  • 2
  • 4
  • 14
  • Angripa ... i tried this but i still could not get it to not show or show the pdf file ! Thank you for your effort ! – Cavemanharris Jun 28 '13 at 11:30
  • I think you can try to catch the length of value in the field and then you make a temp variabel for label. like this $lbl = count($_POST['pdf']) == 0 ? '' : ''; ?> – Angripa Jul 04 '13 at 09:24