Forums
This topic is locked
If statement for record values
Posted 23 Oct 2007 21:32:53
1
has voted
23 Oct 2007 21:32:53 John McCovery posted:
Trying to use a MM:if statement to display a value if one exist in the database. But I don't want the space to be occupied by "white space" if there is no value in the database.Edited by - Jon05 on 23 Oct 2007 22:27:39
Replies
Replied 24 Oct 2007 23:11:01
24 Oct 2007 23:11:01 Alan C replied:
You could move the if test so that the whole line or appropriate part of the page was not shown
Replied 25 Oct 2007 23:44:38
25 Oct 2007 23:44:38 John McCovery replied:
When I try to use the MM:if statement it only allows me to use it for a region of the page. I'm trying to use it for values from the database since some of the records don't have any values in it.
I don't know how to move the if test so that the whole line of the page isn't shown. Any suggestions please.
I don't know how to move the if test so that the whole line of the page isn't shown. Any suggestions please.
Replied 26 Oct 2007 14:41:23
26 Oct 2007 14:41:23 Alan C replied:
I'm not sure that you can make a test like that with only the DW tests, you might have to 'hand code' such a test - I usually do it that way, but there may be someone else who knows the way to do it.
If that would be useful let me know and I'll post a php example, to show or hide a field depending on whether or not it has a value
If that would be useful let me know and I'll post a php example, to show or hide a field depending on whether or not it has a value
Replied 26 Oct 2007 17:19:42
26 Oct 2007 17:19:42 John McCovery replied:
I thought that I probably would have to hand-code something in order to get it to work. I was thinking about maybe some javascript or something. Would you have anything in javascript?
Replied 27 Oct 2007 12:41:56
27 Oct 2007 12:41:56 Alan C replied:
I don't have anything in javascript, but I've got two ways to do it in php with html and CSS
the html way
First, when you are using custom php in dw it generally pays to keep it as short as possible, so that DW can handle all the html bits, it seems to help DW render the pages better. Let's say you want a table row to be conditional on a database field, for example postcode, if there is nothing in the field you don't want to show the row containing the label and the blank value space.
there would be something like - I've modified this from something I had and it's untested
<pre id=code><font face=courier size=2 id=code>
<?php if (strlen($row_rsPropertyUpdate['postcode'])>0)
{
?>
<tr >
<td align="left"><?php if ($errors_found==0)
{
?>
Your listing meets our minimum requirements and will be shown in our search results
<?php }
else
{
?>
Your listing does not yet meet the minimum requirements
<?php }
?><td align="left" >
<?php if ($errors_found==0)
{
?>
<img src="/images/symbols/tick.gif" alt="Yes, this listing meets our minimum requirements" width="60" height="60" />
<?php }
else
{
?>
<img src="/images/symbols/cross.gif" alt="This listing needs more details to meet our minimum requirements" width="60" height="60" />
<?php }
?></td>
</tr>
<?php } ?>
</font id=code></pre id=code>
in that example the whole row depends on the length of the postcode string being greater than zero, there there are conditionals in the cells
another way to do it is with styles that either display or don't display depending on a value, so to do it that way you would start off by defining two styles, like this . . . well these are actually classes that can be applied to any tag which makes them really useful, grab this page and save it as test.php or something like that, then upload it to your server, call it then look at the source, then change the value of something to '' (ie an empty string) and try it again
<pre id=code><font face=courier size=2 id=code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>css tester page</title>
<style>
.doNotShow {
display:none; /*this will prevent anything from being shown*/
}
.errorCondition{
color:red;
background-color:#FFFF00; /*this will show red text on a yellow background*/
}
</style>
</head>
<body>
<?php $something='a'; ?>
<p class="<?php if (strlen($something)>0) {echo 'errorCondition';} else {echo 'doNotShow';}?>">
you will only see this if the string length of $something is greater than zero
</p>
</body>
</html></font id=code></pre id=code>
the html way
First, when you are using custom php in dw it generally pays to keep it as short as possible, so that DW can handle all the html bits, it seems to help DW render the pages better. Let's say you want a table row to be conditional on a database field, for example postcode, if there is nothing in the field you don't want to show the row containing the label and the blank value space.
there would be something like - I've modified this from something I had and it's untested
<pre id=code><font face=courier size=2 id=code>
<?php if (strlen($row_rsPropertyUpdate['postcode'])>0)
{
?>
<tr >
<td align="left"><?php if ($errors_found==0)
{
?>
Your listing meets our minimum requirements and will be shown in our search results
<?php }
else
{
?>
Your listing does not yet meet the minimum requirements
<?php }
?><td align="left" >
<?php if ($errors_found==0)
{
?>
<img src="/images/symbols/tick.gif" alt="Yes, this listing meets our minimum requirements" width="60" height="60" />
<?php }
else
{
?>
<img src="/images/symbols/cross.gif" alt="This listing needs more details to meet our minimum requirements" width="60" height="60" />
<?php }
?></td>
</tr>
<?php } ?>
</font id=code></pre id=code>
in that example the whole row depends on the length of the postcode string being greater than zero, there there are conditionals in the cells
another way to do it is with styles that either display or don't display depending on a value, so to do it that way you would start off by defining two styles, like this . . . well these are actually classes that can be applied to any tag which makes them really useful, grab this page and save it as test.php or something like that, then upload it to your server, call it then look at the source, then change the value of something to '' (ie an empty string) and try it again
<pre id=code><font face=courier size=2 id=code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>css tester page</title>
<style>
.doNotShow {
display:none; /*this will prevent anything from being shown*/
}
.errorCondition{
color:red;
background-color:#FFFF00; /*this will show red text on a yellow background*/
}
</style>
</head>
<body>
<?php $something='a'; ?>
<p class="<?php if (strlen($something)>0) {echo 'errorCondition';} else {echo 'doNotShow';}?>">
you will only see this if the string length of $something is greater than zero
</p>
</body>
</html></font id=code></pre id=code>
Replied 27 Oct 2007 14:05:54
27 Oct 2007 14:05:54 Alan C replied:
here's something else, I was working on an old page and found exactly what you want . . .
<pre id=code><font face=courier size=2 id=code>
<?php if (strlen($row_RsLegacy['a1'])>0) {?>
<tr>
<td class="p80percent"><?php echo $row_RsLegacy['a1']; ?></td>
<td align="center"> </td>
</tr>
<?php }
</font id=code></pre id=code>
on this page I have some old records from a legacy system and only want to show the fields that actually contain data, probably like yours, so that there are no ugly gaps on the page, this works fine, there's also a class that reduces the text size to 80 percent
<pre id=code><font face=courier size=2 id=code>
<?php if (strlen($row_RsLegacy['a1'])>0) {?>
<tr>
<td class="p80percent"><?php echo $row_RsLegacy['a1']; ?></td>
<td align="center"> </td>
</tr>
<?php }
</font id=code></pre id=code>
on this page I have some old records from a legacy system and only want to show the fields that actually contain data, probably like yours, so that there are no ugly gaps on the page, this works fine, there's also a class that reduces the text size to 80 percent
Replied 05 Nov 2007 22:11:18
05 Nov 2007 22:11:18 John McCovery replied:
Well I have never written anything in php. I understand what you are referring to but I don't know
php which makes it a little harder. I will give it a try.
php which makes it a little harder. I will give it a try.