Skip to main content
January 17, 2007
Answered

Hiding/viewing text when field null/not null

  • January 17, 2007
  • 1 reply
  • 406 views
I found out how to only show a field in a query using Dreamweaver 8, PHP, and MySQL when the field value is null by viewing this:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=12&catid=189&threadid=1005921&arctab=arc&highlight_key=y&keyword1=show%20region

However, how do I put text next to the field data when there is data in the field? So, 1) hide text and data when the value in the record field is null, and 2) show text and data when the record field is not null.

I tried to put the text in with the echo, but then the text was displayed without the field data when the field was null.

The code I have so far is:
<?php if (!is_null($row_rsProperties['US_List_Price'])){echo $row_rsProperties['US_List_Price'];} ?>

rsProperties is recordset and US_List_Price is the field

Thanks !
This topic has been closed for replies.
Correct answer Newsgroup_User
dulcey1 wrote:
> I tried to put the text in with the echo, but then the text was displayed
> without the field data when the field was null.
>
> The code I have so far is:
> <?php if (!is_null($row_rsProperties['US_List_Price'])){echo
> $row_rsProperties['US_List_Price'];} ?>

The is_null() function checks for a NULL value. I suspect that your
fields are empty rather than NULL. Change the code to this:

<?php if (!empty($row_rsProperties['US_List_Price'])){echo
'Some text '.$row_rsProperties['US_List_Price'];} ?>


--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

1 reply

Newsgroup_UserCorrect answer
Inspiring
January 17, 2007
dulcey1 wrote:
> I tried to put the text in with the echo, but then the text was displayed
> without the field data when the field was null.
>
> The code I have so far is:
> <?php if (!is_null($row_rsProperties['US_List_Price'])){echo
> $row_rsProperties['US_List_Price'];} ?>

The is_null() function checks for a NULL value. I suspect that your
fields are empty rather than NULL. Change the code to this:

<?php if (!empty($row_rsProperties['US_List_Price'])){echo
'Some text '.$row_rsProperties['US_List_Price'];} ?>


--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
January 17, 2007
That worked ! Thanks so much. I am going to buy your book so I don't have to ask questions like this.