Page 1 of 1
Empty field
Posted: Wed Nov 17, 2004 5:39 am
by snicolas
Is there a quick way to check if 1 or more field is empty.
I am talking php and MSSQL.
thx.
S
Posted: Wed Nov 17, 2004 5:44 am
by phpScott
in what the database or in the script before it gets into the db
Posted: Wed Nov 17, 2004 5:47 am
by snicolas
The db contain records.
I need to check in php if 1 or more field is empty for a recordID.
If all empty i need to display something, if there is 1 field not empty, i need to dispaly something else.
Thx
S.
Posted: Wed Nov 17, 2004 6:06 am
by snicolas
Anybody??please...
Posted: Wed Nov 17, 2004 6:46 am
by kettle_drum
Either check to see if the field is == '' or NULL depending on how your database is set up.
Posted: Wed Nov 17, 2004 8:56 am
by CoderGoblin
Once you have your row, if it is an array you could use the array functions to test it, such as
Code: Select all
if (in_array('',$row)!==false) {
// You have empty
}
Not sure what would happen with null values, you would have to check.
Posted: Wed Nov 17, 2004 10:02 am
by snicolas
thx CoderGob..this did the trick...
Posted: Wed Nov 17, 2004 10:16 am
by php_passerby
If you want to check within the script, I think the best way to do it would be to create an array (associative or enumerated) with
$myArray = mssql_fetch_array($myRecordset);
or
$myArray = mssql_fetch_row($myRecordset);
(I would prefer to use the first form)
Then, you should use a foreach control structure to increment a counter for each null value encountered, like this:
$nullFieldsEncountered = 0;
foreach ($myArray as $key, $value) {
if ($value=="") $nullFieldsEncountered++;
}
At the end of the iteration, you have the number of nulls in the variable!