Skip to main content
Inspiring
October 1, 2010
Answered

Show Region if Field from Recordset is '(not) null'

  • October 1, 2010
  • 1 reply
  • 1545 views

Facing yet another problem. The solution is probably going to be very simple but so far, I haven't figured it out. This is what I'm looking for:

Say you got a newspage displaying the title, message introduction and a read more button. The table in which newsmessages are stored has got 5 columns:

  • ID (primary key, AI)
  • date_entry (timestamp)
  • newstitle
  • newsintroduction
  • newsmessage (can be NULL)

As you can see, the column 'newsmessage' can be NULL because sometimes, there are short messages. What I want to know is, if the column 'newsmessage' is NULL, on the page that displays the news records, the 'read more' link should not be visible. It should only show when the column 'newsmessage' is 'not null', so has got content in it.

Thanks!

This topic has been closed for replies.
Correct answer Lon_Winters

I am indeed using DW server behaviours which makes the code look like this:

<?php do { ?>
<p class="messagedate">Geplaatst:

<?php date_default_timezone_set('Europe/Brussels');

$unixtime = strtotime($row_indexnieuws['geplaatst']); echo date("d/m/Y H:i",$unixtime); ?></p>


<h2 class="messagetitle"><?php echo $row_indexnieuws['titel']; ?></h2>


<div class="messageintro"><?php echo ($row_indexnieuws['inleiding']); ?></div>


<p class="messagemore"><a href="bericht.php?id=<?php echo $row_indexnieuws['id']; ?>">Read More</a></p>


<?php } while ($row_indexnieuws = mysql_fetch_assoc($indexnieuws)); ?>


Is it really a region that you want to show or hide? I guess it could be, but DW normally likes it better when the "region" is its own table row. I don't know how many times, even when I do select the TR tag in the property inspector and apply a Show or Hide server behavior, DW still places the code inside the TR tag in the source code.

So basically, want you want to do is wrap the a tag that contains the Read More text, in an If statement. I don't have the exact syntax for you, my PHP skills are still in development. Perhaps one of the other folks could help out - or if you do have a Show or Hide behavior (when recordset is empty/not empty), take a look at how that code is structured and use it as a guide. But if you're going to use Null/Not Null as your condition, make sure the field actually contains a null value.

1 reply

October 1, 2010

and we're just supposed to KNOW what server side scripting language you're using cause we know you so much. So don't bother posting the necessary details.

derjaanAuthor
Inspiring
October 4, 2010

Sorry PHP that is.

Inspiring
October 4, 2010

Can you paste in the PHP you're currently using to display the recordset? Or, are you using Dreamweaver server behaviors?