I need to put together a method that would allow me to quantify how many fields in a row have been filled by a user.
For example:
User Name Age Country Gender Height
1 Mike 34 USA Male 6
2 Bill 23 CA 5
3 Jane 31 USA
In the above example, I would like to query the database and return a value that would reflect the degree of completion of the user's record. Such as:
User 1 = 100% complete
User 2 = 80% complete
User 3 = 60% complete
I wonder if this needs to be done via SQL clauses or if via PHP SQL functions one could query the DB and calculate the degree of completion.
Any suggestions how to do this? I am using PHP 5 (codeigniter) and SQL 5.0.77, but any roadmap would be greatly appreciated.
解决方案$result = mysql_query('SELECT * FROM `MyTable`');
while($row = mysql_fetch_row($result)){
$empty_count = 0;
$count = count($row);
for($i = 0; $i < $count; $i++)
if($row[$i] === '' || $row[$i] === 'NULL')
$empty_count++;
echo 'User '.$row[0].' = '.((int)(100*(1-$empty_count/($count-1)))).'% complete';
}