473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

or condition in an ifelse statement

Hi all

I want to specify an OR condition in an if statement. Can anyone please tell me how this can be done.
I've tried this but it does not work

[PHP]<? if (($add!=1) or (!empty($row["Bkg_Renewal_Dt"])))
{
echo '<tr>';
echo '<td class="hr">';echo htmlspecialchars("Renewal Date")."&nbsp;" ;echo '</td>';?>
<td class="dr"><input type="text" readonly name="Bkg_Renewal_Dt" value="<? echo str_replace('"', '&quot;', trim($row["Bkg_Renewal_Dt"])) ?>"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].Bkg_Renewal_Dt,'yyyy-mm-dd',this)">
<? echo '</td>';
echo '</tr>';
} ?>[/PHP]

Thanks
Jul 4 '07 #1
5 1469
dafodil
392 256MB
Hi all

I want to specify an OR condition in an if statement. Can anyone please tell me how this can be done.
I've tried this but it does not work

[PHP]<? if (($add!=1) or (!empty($row["Bkg_Renewal_Dt"])))
{
echo '<tr>';
echo '<td class="hr">';echo htmlspecialchars("Renewal Date")."&nbsp;" ;echo '</td>';?>
<td class="dr"><input type="text" readonly name="Bkg_Renewal_Dt" value="<? echo str_replace('"', '&quot;', trim($row["Bkg_Renewal_Dt"])) ?>"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].Bkg_Renewal_Dt,'yyyy-mm-dd',this)">
<? echo '</td>';
echo '</tr>';
} ?>[/PHP]

Thanks
Replace the if part with this:

if (($add!=1)||(!empty($row["Bkg_Renewal_Dt"])))

**Note the character is a pipe character ||

Hope this helps
Jul 4 '07 #2
pbmods
5,821 Expert 4TB
Alternatively, you can do this:
Expand|Select|Wrap|Line Numbers
  1. if (! (($add == 1) && empty($row['Bkg_Renewal_Dt'])))
if you want to save a CPU cycle or two (note also single quotes around 'Bkg_Renewal_Dt').

Also, if empty($row['Bkg_Renewal_Dt']) is more likely to occur, it should come before ($add == 1) in the conditional to encourage short-circuits.
Jul 4 '07 #3
Hi

Is there something wrong with the code below. I've tried the solution you proposed but it is not working. If the variable $add is not equal to one and the renewal date contains a value then only should the textbox for the renewal date be displayed otherwise if add==1 or if the renewal date does not contain any value the textbox to edit the renewal date should not be displayed


[PHP]
some other codes
</tr>
if (! (($add == 1) && (empty($row['Bkg_Renewal_Dt'])))) //if not adding and if renewal date is not empty display renewal dt else not
{ ?>
<tr>
<td class="hr"><? echo htmlspecialchars('Renewal Date')."&nbsp;" ?></td>
<td class="dr"><input type="text" readonly name="Bkg_Renewal_Dt" value="<? echo str_replace('"', '&quot;', trim($row['Bkg_Renewal_Dt'])) ?>"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].Bkg_Renewal_Dt,'yyyy-mm-dd',this)">
</td>
</tr>
<? } ?>
<tr>
some other codes
[/PHP]

Thanks for your help
Jul 5 '07 #4
dafodil
392 256MB
Hi

Is there something wrong with the code below. I've tried the solution you proposed but it is not working. If the variable $add is not equal to one and the renewal date contains a value then only should the textbox for the renewal date be displayed otherwise if add==1 or if the renewal date does not contain any value the textbox to edit the renewal date should not be displayed


[PHP]
some other codes
</tr>
if (! (($add == 1) && (empty($row['Bkg_Renewal_Dt'])))) //if not adding and if renewal date is not empty display renewal dt else not
{ ?>
<tr>
<td class="hr"><? echo htmlspecialchars('Renewal Date')."&nbsp;" ?></td>
<td class="dr"><input type="text" readonly name="Bkg_Renewal_Dt" value="<? echo str_replace('"', '&quot;', trim($row['Bkg_Renewal_Dt'])) ?>"><input type="button" value="Cal" onclick="displayCalendar(document.forms[0].Bkg_Renewal_Dt,'yyyy-mm-dd',this)">
</td>
</tr>
<? } ?>
<tr>
some other codes
[/PHP]

Thanks for your help

I noticed that you separated some parts of the codes...

Can you put all your codes inside the php tag like this:
<?php
codes....



?>

Please don't forget to echo some html tags over there....

Please write your programs in a structured manner so that you can see what line causes the error....

If there are still errors please post the error...
Jul 5 '07 #5
ak1dnar
1,584 Expert 1GB
Me too waiting for your original coding......
Jul 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: news | last post by:
I'm trying out the Zend Development Environment 4, and for the most part I like it, except for two things. It seems to think certain lines that are perfectly valid are bugs. Like this: while...
2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
2
by: mr_mach7 | last post by:
I have a situation in which I want to dynamically build a SQL statement based upon criteria. The statement would contain different fields depending upon the criteria. I created a Stored Procedure...
1
by: Daniel Bass | last post by:
Using VC#.Net, I want to take a statement, that loosely follows the rules of an SQL'a "WHERE" statement, and determine whether that statement is true or false. For example: ( ( Head = 'abc')...
5
by: Lisa J. | last post by:
Heloe I would like to be able to pass a condition of an IF statement as parameter as follow aStr=” (A=1) and (B=2)” if aFunc(“aStr”) then …. End if
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
2
by: Sorin Schwimmer | last post by:
I am thinking on something in the following form: <code> import time import thread delay=True def fn() global delay
5
by: jimc52 | last post by:
Hello Everyone: I am hoping one of the gurus here will give me some help. I have designed a form with some check boxes. I put the checkboxes there on the form so later I could use them as flags on...
2
by: Ely | last post by:
Can some one write me the code in Visual Basic for an expretion similar to the Where Condition to open a report? I can't use the Where Condition because it pop up a message of Microsoft database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.