Forum Moderators: open

Message Too Old, No Replies

checking for null status's from database

checking for null status's from database

         

adrianbromfield

11:03 am on Sep 18, 2008 (gmt 0)

10+ Year Member



Hey guys, im creating a script which pulls data from an sql database and it prints it into a file, issue being some fields are writing in the file "null".. which i dont wont!

so..

i added this as i couldnt find a function already to do it:

function isNull(val) {
if(val == null ¦¦ val == "null"){
return "";
}
else{
return val;
}
}

now funny enough it still writes "null" into my file! Anybody had anything like this before who knows how to get around this situation?

Thanks for any help in advance..

Adrian

Fotiman

1:24 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does val maybe contain some whitespace? For example:
"null "
?

adrianbromfield

1:40 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



no, its doesnt actually contain anything, i wrote that into the if statement incase for some reason it was reading it as text but the field is actually empty but because its empty its classed as null, and for some reason writes that in. but I have double checked what you have mentioned incase but there doesnt appear to be any white spaces where it is printing it in the file.

Fotiman

1:59 pm on Sep 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would probably suggest debugging it with Firefox and the Firebug plugin. Firebug lets you set breakpoints, so I would set a breakpoint at the line containing your "if" conditional, then see what Firebug thinks "val" is.

Alternatively, maybe throw in an alert message like:

alert("val = (" + val + ")"); 
if (val != null) {
alert("val.length = " + val.length);
}

adrianbromfield

3:15 pm on Sep 18, 2008 (gmt 0)

10+ Year Member



unfortunatley I am unable to do that, the script isnt actually within a web page, it will be ran via a scheduled task each do to collect images and such and then transfer them to another location on a remote machine.

Maybe some other tools that do this from the file itself that you may know of?