Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

check with null

Recommended Posts

I am creating a file handling script.
If no file was uploaded, or they didn't try I am registering the url, and the name of the file with null for database entry like
$tempfile = "null";
$tempfileurl = "null";
putting that into the database, later can I say
[code]<?php
while ($row = mysql_fetch_array(whatever)) {
  if ($tempfile != "null") {
    // do what is necessary to show the file
  }else {
    // act like the file was never there
  }
}
?>[/code]
would thatr work in testing for the file??

Share this post


Link to post
Share on other sites
[code=php:0]
<?php
while ($row = mysql_fetch_array(whatever)) {
  if ($tempfile != Null) {
    // do what is necessary to show the file
  }else {
    // act like the file was never there
  }
}
?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=businessman332211 link=topic=108928.msg438755#msg438755 date=1158849183]
would thatr work in testing for the file??
[/quote]

why not try it and then come to us if you are having problems? a good portion of learning is simply trial and error with things like this.

as a side note, if you're looking to see whether a file has been uploaded, simply check out the function file_exists().

Share this post


Link to post
Share on other sites
It would better to construct a IF() in your SELECT part of the query and return some flag from the test, than to use NULL in your db table. It's really a bad idea to use NULL in a database, if you don't understand why, then you need to do some reading!

me!

Share this post


Link to post
Share on other sites
[quote author=printf link=topic=108928.msg438763#msg438763 date=1158849834]
It's really a bad idea to use NULL in a database, if you don't understand why, then you need to do some reading!
[/quote]
sounds like [b]you[/b] need to [url=http://www.dbdebunk.com/page/page/1858002.htm]do a little more reading[/url] yourself ;) ... yes, there are some valid arguments why NULL shouldn't be used in some cases, but there are also valid arguments for some cases to use them. as explained in the article, most of the arguments you read are criticism of SQL and how it handles NULL, not of NULL itself. NULL is a valid data form, and when handled properly can be very useful.

Share this post


Link to post
Share on other sites
I was given the advice about null, from one of the best mysql/database people on the internet right here in this forum, named, fenway, and I doubt if you knew even a quarter of what he knows, so I think I will take his advice on this one.  He gave me advice about this awhile back, and when I finished hte system, and didn't listen to him, I am severely regretting it now, he said "null" is the best one to use(for what I was trying to do), I didn't listen to what he said, and I lost about a week worth of development time.  So I will stick with what he said from now on.

Share this post


Link to post
Share on other sites
If you think it's good to use, then I am happy for you! But because it over used and used most times out of context, (used without knowing what it really does) it should never be used! Sorry if my statement offended you, but using null in scripting is totally different than * NULL -> unknown * in your database logic!


me!

Share this post


Link to post
Share on other sites
I dont' really get offended but

[quote] if you don't understand why, then you need to do some reading![/quote]
That was slightly more than annoying, but I suppose I can understand where your coming from.

Share this post


Link to post
Share on other sites
[quote author=businessman332211 link=topic=108928.msg438784#msg438784 date=1158853407]
I dont' really get offended but

[quote] if you don't understand why, then you need to do some reading![/quote]
That was slightly more than annoying, but I suppose I can understand where your coming from.
[/quote]

I guess I should have been clearer, that statement did sound sort of lame, sorry, I will try better to explain myself next time!


me!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.