Page 1 of 1
What Wrong with this Simple Conditional Script?
Posted: Thu Jan 22, 2004 10:19 am
by theoph
Please excuse my ignorance as I'm a newbie, but why is the following conditional argument not working? I'm getting the statment part of the script when the conditional data ($row_rsDisplay) meets one or both of the listed conditions.
Code: Select all
<?php if((($row_rsDisplay['wedding']) != '00-00') || (!empty($row_rsDisplay['wedding'])))
{ echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];}?>
-Dave
Posted: Thu Jan 22, 2004 10:22 am
by malcolmboston
Code: Select all
<?php
if
{
(($row_rsDisplay['wedding']) != '00-00') || (!empty($row_rsDisplay['wedding']))
}
else
{
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}?>
does that work
Posted: Thu Jan 22, 2004 10:27 am
by microthick
Isn't an && warranted in this situation and not || ?
Code: Select all
// Only output Aniversary if wedding is not empty and not equal to 00-00
if (($row_rsDisplay['wedding']) != '00-00') && (!empty($row_rsDisplay['wedding'])) {
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}
Posted: Thu Jan 22, 2004 10:28 am
by malcolmboston
microthick wrote:Isn't an && warranted in this situation and not || ?
Code: Select all
// Only output Aniversary if wedding is not empty and not equal to 00-00
if (($row_rsDisplay['wedding']) != '00-00') && (!empty($row_rsDisplay['wedding'])) {
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}
sorry, microthick is right, however i dont understand the format in the code that was provided first

, maybe its just me, im starting to get programmers fatigue after (insert stupid amounts of hours) in a row sat at the computer
Posted: Thu Jan 22, 2004 11:22 am
by theoph
Got it to work using the following script, but there must be a better way to write it though.
Code: Select all
<?php if(($row_rsDisplay['wedding']) == '00-00')
{}
elseif(empty($row_rsDisplay['wedding']))
{}
else
{
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}
?>
-DAVE
Posted: Thu Jan 22, 2004 11:38 am
by markl999
Code: Select all
if($row_rsDisplay['wedding'] == '00-00') $row_rsDisplay['wedding'] = '';
if(!empty($row_rsDisplay['wedding'])){
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}
?
Posted: Thu Jan 22, 2004 11:42 am
by m3rajk
theoph wrote:Got it to work using the following script, but there must be a better way to write it though.
Code: Select all
<?php
if(($row_rsDisplay['wedding']) == '00-00')
{}
elseif(empty($row_rsDisplay['wedding']))
{}
else
{
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding'];
}
?>
-DAVE
there most definitely is.
in a case whre you have several tests, for serveral different options, switch is faster. your style would be better suited for switch.
microthick's is better for using an if. here it is with many more comments
Code: Select all
<?php
// Only output Aniversary if wedding is not empty and not equal to 00-00
if (($row_rsDisplay['wedding']) != '00-00') # test that it's not equal to '00-00'
&& # and set another conditionthat MUST be met
(!empty($row_rsDisplay['wedding'])) { # make that not being empty
echo '<span class="underline">Anniversary:</span> ' . $row_rsDisplay['wedding']; # do what needs to be done then
}
?>
Posted: Thu Jan 22, 2004 11:58 am
by theoph
Learn something every day.
Thanks for all the imput guys.
