0

I have a form displaying in a table dynamically working properly but my issue is if one field is empty in database in front end I want to hide that field. Here is my view code:

<?php
         foreach($jobs as $row)
         {
              ?>
               <tr>
               <?php
               if($row->job_advantage_skills = '')
               {?>
               <td valign="middle"><strong>Advantage:</strong><?php echo $row->job_advantage_skills; ?></td>
               <?
               }
               ?>
               </tr>
           <?
            }
            ?>

Here I have given if($row->job_advantage_skills = '') {} for this I want to hide if there is advantage skills hide this field in front end.

Alyona Yavorska
  • 569
  • 2
  • 14
  • 20
user3496799
  • 7
  • 2
  • 8

4 Answers4

2

I think you want to hide the field if '$row->job_advantage_skills' is empty:-

So, instead of using (= or == or ===) you have to use != (not equals to)

So, your code will be:-

<?php
           if($row->job_advantage_skills != '')
           {?>
               <td valign="middle"><strong>Advantage:</strong><?php echo $row->job_advantage_skills; ?></td>
           <?
           }
?>

OR

You can also use [ !empty() ]:-

<?php
               if(!empty($row->job_advantage_skills))
               {?>
                   <td valign="middle"><strong>Advantage:</strong><?php echo $row->job_advantage_skills; ?></td>
               <?
               }
    ?>
DWX
  • 2,282
  • 1
  • 14
  • 15
1

in if statement Dont assign the value

use

    if($row->job_advantage_skills == '')

instead of

   if($row->job_advantage_skills = '')
                                ^ 

For hide

<tr>
               <?php
               if($row->job_advantage_skills == '')
               {?>
                      // add class for hide
               <td class="hide" valign="middle "><strong>Advantage:</strong><?php echo $row->job_advantage_skills; ?></td>
               <?
               }
               ?>
               </tr>

CSS

.hide{
display:none;
}

Balachandran
  • 9,567
  • 1
  • 16
  • 26
0

you just set the value for $row->job_advantage_skills = "". if check condition is null put == or ===

if($row->job_advantage_skills == '')
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
0
  1. Use ==/=== not =. Check php comparison operators.
  2. To hide the <td> use display:none or add a css class with display:none property.

<?php
if($row->job_advantage_skills == '')
{?>

   <td valign="middle" style="display:none"><strong>Advantage:</strong><?php echo $row->job_advantage_skills; ?></td>

<?
}
?>
Shaunak D
  • 20,588
  • 10
  • 46
  • 79