views:

31

answers:

5

I've created a dynamic table that will pull information from a database. However, there is 1 field that may have NOTHING in it, or it may have a bunch of information (from multiple check boxes) in it. I am trying to condense the initial table view (the details will show full db field information). What I have right now is this:

if $row['extras'] = ''{
print '';
} else {
print 'Y';

By this code, it displays "Y" in ALL fields, rather than what is needs to. Am I on the right track or completely off base?

+1  A: 

think there's a typo, the code assigns (with one equals sign) rather than checks equality (2 equals signs)

jspcal
Thanks...changed and it worked. Simple...what can I say, I'm a noob!
A: 

You should check it for being null:

if ($row['extras'] == null)
{
    print '';
}
else
{
   print 'Y'
};
alemjerus
A: 

You could test it with sql query like this

SELECT * FROM table WHERE field IS NOT NULL; 
streetparade
A: 

Try this code instead:

if (trim($row['extras']) != '')
{
    echo 'Y';
}

Alternatively you can issue a SQL query that goes something like this:

SELECT * FROM yourTable WHERE extras NOT LIKE '';
Alix Axel
A: 

while the snippet you show is syntactically invalid, which betrays that it's not your actual code (and hence people who answer risk losing their time chasing red herrings), i'm pretty sure it also displays your actual problem:

if ($foo = '') {
   echo "empty";
} else {
   echo "contains " . strlen($foo) . " characters";
}

this code prints contains 0 characters. this exact kind of bug led me to write comparisons with the constant operand on the left side:

if ('' = $foo) {
   echo "empty";
} else {
   echo "contains " . strlen($foo) . " characters";
}

this causes an error, which is preferable to going on with unexpected values.

just somebody