1

I have a table name users. This table having 25 columns.

After login i have updated some fields. Now i want to know how many column is blank(null value).

It is not possible to use if...elseif...else condition. Is there any single query to get the all null value fields?

Please write your answer

Thanks

EDIT:

Code:

$getUser=mysql_fetch_array(mysql_query("SELECT * FROM users"));
if($getUser['field1']==''){
    //field1 is blank
}elseif($getUser['field2']==''){
    //field2 is blank
}elseif($getUser['field3']==''){
    //field3 is blank
}
.
.
.
elseif($getUser['field25']==''){
    //field25 is blank
}
Developer
  • 2,676
  • 8
  • 43
  • 65

3 Answers3

2

use below query:

select * from mytable 
where field1 is null or field2 is null or .....field25 is null;
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30
  • Your query is working fine. Suppose i have 200 columns now how to write that query? It is not possible to write `field1 is null or field2 is null.....field200 is null` Is there any shortcut query? – Chinmay235 May 02 '14 at 06:20
1
$users=mysql_fetch_array(mysql_query("SELECT * FROM users"));

foreach ($users as $user) {
    $count = 0;
    foreach ($user as $column_name => $column) {
        if ($column == '')
            $count++;
    }

    echo $count."\n";
}

if you want to get more information about which column is null, you can echo $column_name

Hieu Vo
  • 3,105
  • 30
  • 31
-1

To get a row with a null column you can use this query:

SELECT LastName,FirstName,Address FROM Users
WHERE Address IS NULL

If you want to know how many column is blank(null value), it will be better if you SELECT * that spesific-user and check the result through php..

Bla...
  • 7,228
  • 7
  • 27
  • 46