Reputation: 2706
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
}
Upvotes: 1
Views: 550
Reputation: 3274
$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
Upvotes: 1
Reputation: 7288
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..
Upvotes: -1
Reputation: 6844
use below query:
select * from mytable
where field1 is null or field2 is null or .....field25 is null;
Upvotes: 2