473,394 Members | 1,663 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,394 software developers and data experts.

If statement question

Hi there,

I have the following code:

echo "\n <address>";
if ($entry_info[location] and $entry_info[location] != '') {
echo "\n ".stripslashes($entry_info[location]).".,";
}
if ($entry_info[address1] and $entry_info[address1] != '' ) {
echo "\n ".stripslashes($entry_info[address1]);
}
if ($entry_info[address2] and $entry_info[address2] != '' ) {
echo ',';
echo "\n ".stripslashes($entry_info[address2]);
}
If the mysql database does not have the field populated I do not want the .,
to appear in the address.
What can I put to show not equal to any data in the database.

Thanks in advance for your help.
Smriti
Jul 17 '05 #1
3 3382

On 8-Dec-2003, "Smriti Dev" <sm********@utoronto.ca> wrote:
I have the following code:

echo "\n <address>";
if ($entry_info[location] and $entry_info[location] != '') {
echo "\n ".stripslashes($entry_info[location]).".,";
}
if ($entry_info[address1] and $entry_info[address1] != '' ) {
echo "\n ".stripslashes($entry_info[address1]);
}
if ($entry_info[address2] and $entry_info[address2] != '' ) {
echo ',';
echo "\n ".stripslashes($entry_info[address2]);
}
If the mysql database does not have the field populated I do not want the
.,
to appear in the address.
What can I put to show not equal to any data in the database.


If the location column is a CHAR, it is fixed length and the database will
return that length of spaces. Comparing it to '' will not work. You could
compare to ' ' (the appropriate number of spaces) or use trim() to
remove the spaces.

You should be coding quotes or apostrophies around your column names (unless
you've defined them as constants or they are in a double quoted string), for
example:
if ($entry_info['location'] and trim($entry_info['location'])!='')

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
"Smriti Dev" <sm********@utoronto.ca> wrote in message news:<Hp********@campus-news-reading.utoronto.ca>...
Hi there,

I have the following code:

echo "\n <address>";
if ($entry_info[location] and $entry_info[location] != '') {
echo "\n ".stripslashes($entry_info[location]).".,";
}
if ($entry_info[address1] and $entry_info[address1] != '' ) {
echo "\n ".stripslashes($entry_info[address1]);
}
if ($entry_info[address2] and $entry_info[address2] != '' ) {
echo ',';
echo "\n ".stripslashes($entry_info[address2]);
}
If the mysql database does not have the field populated I do not want the .,
to appear in the address.
What can I put to show not equal to any data in the database.

Thanks in advance for your help.
Smriti

Hi Smriti,

I assume the location field in your database is string.

There are two possibilities:-

1. If you declare the field as *NULL-allowed field*

You can check for NULL value with is_null($entry_info['location']) function

2. If the field in database is declared as *NOT NULL field*
You can check for empty string $entry_info['location'] ==""
I think better way to do this checking is by merging these two conditions
with a single statement:

empty($entry_info['location'])

It will return false only when your location field is populated and non empty.

-- Rahul
Jul 17 '05 #3
"Smriti Dev" a écrit le 08/12/2003 :
I have the following code:

echo "\n <address>";
if ($entry_info[location] and $entry_info[location] != '') {
echo "\n ".stripslashes($entry_info[location]).".,";
}
if ($entry_info[address1] and $entry_info[address1] != '' ) {
echo "\n ".stripslashes($entry_info[address1]);
}
if ($entry_info[address2] and $entry_info[address2] != '' ) {
echo ',';
echo "\n ".stripslashes($entry_info[address2]);
}
If the mysql database does not have the field populated I do not want the .,
to appear in the address.
What can I put to show not equal to any data in the database.


Sorry I don't get your question... Maybe because it's late...
You statement if ($entry_info[adress2]) is not very clear and clean,
what do you want to test there? Do you mean isset()?

--
Have you read the manual?
http://www.php.net/manual/en/

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Greg Ofiesh | last post by:
Anyone who can help, I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign key relating to K2. My...
94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
21
beacon
by: beacon | last post by:
Hello to everybody, I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know),...
10
by: JohnO | last post by:
Hi All, This question is related to iSeries V5R4 and db2. I want to implement an AFTER DELETE trigger to save the deleted rows to an archive table, I initially defined it as a FOR EACH...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.