isset - right way to go ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

isset - right way to go ?

Post by aravona »

I have a tiny snippet of code which I want to use, based on if three table options have been filled in or not.

The options will be NULL for 90% of the time, but for those that aren't I want to use the following:

Code: Select all

<?php if(isset($row2->ccolour)){
?>
<tr style="<?=$bgcolor?>">
<td width="85%" align="left" colspan="8"><?=$row2->pack?> <img src="<?=$row2->ccolour?>" /> <img src="<?=$row2->tcolour?>" /></td>
</tr>
<?php 
}
?>
Basically to show some pictures and a few words from the database, however (not my code to start with and most of the site is icky) but the isset($row2->ccolour) doesnt work, the extra table line comes up for empty sets too.

The other thing I want to do is to make sure this happens if ANY of those three options, pack, ccolour and tcolour have been chosen (maybe best for me to split it up?)

Thanks in advance,

Aravona
User avatar
Alex-V
Forum Newbie
Posts: 17
Joined: Mon Jul 19, 2010 3:53 pm

Re: isset - right way to go ?

Post by Alex-V »

isset just checks does variable exists no mater what is the value of that var. Maybe you should try this

Code: Select all

if(!empty(row2->ccolour))
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: isset - right way to go ?

Post by aravona »

works ^^ ty ty ! :)
Post Reply