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
}
3
  • Please write your attempt Commented May 2, 2014 at 5:57
  • Hi i have update my question Please check. Commented May 2, 2014 at 6:24
  • possible duplicate of MySQL SELECT only not null values Commented May 2, 2014 at 6:38

3 Answers 3

2

use below query:

select * from mytable 
where field1 is null or field2 is null or .....field25 is null;
Sign up to request clarification or add additional context in comments.

1 Comment

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?
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

Comments

-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..

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.