Re: [PHP] Getting my head around nulls

2001-09-26 Thread Ben . Edwards







Steve Cayford [EMAIL PROTECTED] on 25/09/2001 17:28:57



To:   [EMAIL PROTECTED]
cc:   [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject:  Re: [PHP] Getting my head around nulls


On Tuesday, September 25, 2001, at 10:30  AM, [EMAIL PROTECTED]
wrote:


 Just had a look at manual, ifnull() seems close to useless.  However if
 they had NVL(), as Oracle douse

 NVL( column|litrel, '*null*' )

 This takes a column or literal as its first arg and if arg is null
 returns
 2nd arg otherwise returns arg.  In other words if the column is null it
 is
 replaces by arg2 otherwise it is simply returned.


Um, that's what ifnull() does. At least it works for me.

-Steve

Verry true, sorry, was looking at nullif.  Also noticed the if function,
can this have more than three parameters.  i.e

if ( col, 'A', 'Accept', 'C', 'Complete', 'Unknown' )

like Oracle decode. and if elseif else structure.

Neb










-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


Re: [PHP] Getting my head around nulls

2001-09-26 Thread Steve Cayford


On Wednesday, September 26, 2001, at 02:48  AM, [EMAIL PROTECTED] 
wrote:







 Steve Cayford [EMAIL PROTECTED] on 25/09/2001 17:28:57



 To:   [EMAIL PROTECTED]
 cc:   [EMAIL PROTECTED], [EMAIL PROTECTED]
 Subject:  Re: [PHP] Getting my head around nulls


 On Tuesday, September 25, 2001, at 10:30  AM, [EMAIL PROTECTED]
 wrote:


 Just had a look at manual, ifnull() seems close to useless.  However 
 if
 they had NVL(), as Oracle douse

 NVL( column|litrel, '*null*' )

 This takes a column or literal as its first arg and if arg is null
 returns
 2nd arg otherwise returns arg.  In other words if the column is null 
 it
 is
 replaces by arg2 otherwise it is simply returned.


 Um, that's what ifnull() does. At least it works for me.

 -Steve

 Verry true, sorry, was looking at nullif.  Also noticed the if function,
 can this have more than three parameters.  i.e

 if ( col, 'A', 'Accept', 'C', 'Complete', 'Unknown' )

 like Oracle decode. and if elseif else structure.

 Neb


Looks like you want the CASE statement. I haven't used it but it looks 
pretty much like what you're asking.

CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN 
result ...] [ELSE result] END

Guess this discussion should really be on php-db :)

-Steve

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting my head around nulls.

2001-09-25 Thread Ben . Edwards

I wish the rest of the world saw it that way! But not so...

That's what capitalism does for you -;)

You may want to look at MySQL's IS_NULL function for retrieving data.
Other
than that, I don't have any good advice. It seems that if you retrieve a
NULL from the database and try to assign it to a PHP variable, that
variable
gets destroyed. AFAIK, yes, you need a bunch of data checks, both putting
data in and pulling it back out.

Strange, I did a search on is_null in the MySQL manual (ver 3.23.40 .pdf)
and got no nits on is_null.  Could you provide example of its use.

Neb


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Getting my head around nulls.

2001-09-25 Thread Andrey Hristov

SELECT * from some_table WHERE some_field IS NULL;


Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS

- Original Message - 
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, September 25, 2001 4:09 PM
Subject: RE: [PHP] Getting my head around nulls.


 I wish the rest of the world saw it that way! But not so...
 
 That's what capitalism does for you -;)
 
 You may want to look at MySQL's IS_NULL function for retrieving data.
 Other
 than that, I don't have any good advice. It seems that if you retrieve a
 NULL from the database and try to assign it to a PHP variable, that
 variable
 gets destroyed. AFAIK, yes, you need a bunch of data checks, both putting
 data in and pulling it back out.
 
 Strange, I did a search on is_null in the MySQL manual (ver 3.23.40 .pdf)
 and got no nits on is_null.  Could you provide example of its use.
 
 Neb
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting my head around nulls.

2001-09-25 Thread Johnson, Kirk

 SELECT * from some_table WHERE some_field IS NULL;
 
 
 Andrey Hristov
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: 
 [EMAIL PROTECTED]

Thanks for correcting my misspelling, Andrey, IS NULL not IS_NULL.
Another thing to look at, Ben, is IFNULL(). I would give you an example, but
I never got it to work like I thought it should ;) I think it is supposed to
return an alternate value for NULLs.

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting my head around nulls.

2001-09-25 Thread Ben . Edwards


Just realised, you meant 'is null' not is_null.  Sorry, couldn't see the
wood for the trees.  This in ANSI  SQL and I use it every day.

Had a look at zootweb.com.  And I thought ASP meant 'Active Server Pages'
not 'Application Service Provider'.  And not a zoot suit in sight -;)

Regards,
Neb


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting my head around nulls

2001-09-25 Thread Ben . Edwards

Thanks for correcting my misspelling, Andrey, IS NULL not IS_NULL.
Another thing to look at, Ben, is IFNULL(). I would give you an example,
but
I never got it to work like I thought it should ;) I think it is supposed
to
return an alternate value for NULLs.

Just had a look at manual, ifnull() seems close to useless.  However if
they had NVL(), as Oracle douse

NVL( column|litrel, '*null*' )

This takes a column or literal as its first arg and if arg is null returns
2nd arg otherwise returns arg.  In other words if the column is null it is
replaces by arg2 otherwise it is simply returned.

Next week I will sing the prases of the oracle decode statement -;)  The
week after that I will get all exited about MySQL freetext indexes, yum,
yum.

Neb


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Getting my head around nulls

2001-09-25 Thread Steve Cayford

On Tuesday, September 25, 2001, at 10:30  AM, [EMAIL PROTECTED] 
wrote:

 Thanks for correcting my misspelling, Andrey, IS NULL not IS_NULL.
 Another thing to look at, Ben, is IFNULL(). I would give you an 
 example,
 but
 I never got it to work like I thought it should ;) I think it is 
 supposed
 to
 return an alternate value for NULLs.

 Just had a look at manual, ifnull() seems close to useless.  However if
 they had NVL(), as Oracle douse

 NVL( column|litrel, '*null*' )

 This takes a column or literal as its first arg and if arg is null 
 returns
 2nd arg otherwise returns arg.  In other words if the column is null it 
 is
 replaces by arg2 otherwise it is simply returned.


Um, that's what ifnull() does. At least it works for me.

-Steve



 Next week I will sing the prases of the oracle decode statement -;)  The
 week after that I will get all exited about MySQL freetext indexes, yum,
 yum.

 Neb


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Getting my head around nulls.

2001-09-24 Thread Johnson, Kirk

 And remember 0 as a number is as important as any other number.

I wish the rest of the world saw it that way! But not so...

You may want to look at MySQL's IS_NULL function for retrieving data. Other
than that, I don't have any good advice. It seems that if you retrieve a
NULL from the database and try to assign it to a PHP variable, that variable
gets destroyed. AFAIK, yes, you need a bunch of data checks, both putting
data in and pulling it back out.

Kirk

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: Monday, September 24, 2001 8:59 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Getting my head around nulls.
 
 
 First recap (been doing RDBMS stuff for over 10 years so 
 reckon this is
 correct).  Nulls and blank are NOT the same in RDBMS (in fact 
 there are
 actually several types of nulls).  MySQL implements this 
 correctly (Unlike
 Oracle which treats null and blank the same).  Up to now I am 
 OK but when
 it comes to codeing in PHP I am not to sure about best practice.
 
 The app I am working on for number datatypes inserts 0 if no data is
 entered in form.  I can see why, I am inserting a blank into 
 the database
 and MySQL goes (Hang on this is a number fields and as you are not
 inserting NULL you obviously mean zero).  So I guess I need to do some
 conditional stuff so the blanks are not actually inserted or 
 put null into
 the PHP variable and insert this (Can PHP vars be null but 
 exist?).  Or is
 their another option?
 
 The second half of the issue is getting data from the 
 database.  I added a
 couple of columns to database but then I tried to retrieve them as
 $row[index]. I got a variable x douse not exist error.  This 
 really through
 me until I realised it was because the value in the database 
 was null and
 it kind of makes sense not to create the var for nulls 
 (although it makes
 coding a pig).  So again, it seems I need to do a lot of isset() stuff
 which is going to be a pain.  Any other insight.
 
 Nulls with varchar/char types are not so much of a problem as 
 long as you
 don't mind all fields in the database being blank rather than 
 null after
 you first insert data into them.
 
 It would be good to get peoples advice on this.
 
 And remember 0 as a number is as important as any other number.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]