Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Oct 01, 2010 Oct 01, 2010

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!

TOPICS
Server side applications
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 04, 2010 Oct 04, 2010

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 ar

...
Translate
Guest
Oct 01, 2010 Oct 01, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 03, 2010 Oct 03, 2010

Sorry PHP that is.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 04, 2010 Oct 04, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2010 Oct 04, 2010

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)); ?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 04, 2010 Oct 04, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 06, 2010 Oct 06, 2010
LATEST

Thank you, your post made me think less deeper and more simple which led me to a rather easy solution. Duplicating the recordset used to display the messages and attaching an if statement to that:

<?php $readmore=$row_news['message']; if ($readmore != NULL) { ?>
<p class="messagemore"><a href="../message.php?id=<?php echo $row_news['id']; ?>">Read More</a></p>
<?php } else {echo "";} ?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines