Is there a quick way to check if 1 or more field is empty.
I am talking php and MSSQL.
thx.
S
Empty field
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Once you have your row, if it is an array you could use the array functions to test it, such as
Not sure what would happen with null values, you would have to check.
Code: Select all
if (in_array('',$row)!==false) {
// You have empty
}- php_passerby
- Forum Newbie
- Posts: 6
- Joined: Fri Oct 03, 2003 9:41 am
- Location: El Salvador
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!
$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!