By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

If statement question

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

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

P: n/a
"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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.