我需要组合一个方法,该方法将允许我量化一行中有多少个字段已被用户填充。 并返回一个反映用户记录完成程度的值。这种计算一行中有多少个MySQL字段从两个表中填充(或空)
as:
User 1 = 100% complete
User 2 = 80% complete
User 3 = 60% complete
它在这里同样的问题Counting how many MySQL fields in a row are filled (or empty)
,但如果我需要从表4与ID查询呢?
我这样做是试图
<?php
$userId = $pro->id;
$completeProfile = $db->prepare("SELECT * FROM hired_person_info WHERE id=?");
$completeProfile = $db->prepare("SELECT * FROM hired_education_info WHERE id=?");
$completeProfile = $db->prepare("SELECT * FROM hired_job_info WHERE id=?");
$completeProfile = $db->prepare("SELECT * FROM hired_ts_info WHERE id=?");
$completeProfile->bind_param('i', $userId);
if ($completeProfile->execute()) {
$result = $completeProfile->get_result();
while ($row = $result->fetch_row()) {
$empty_count = 0;
$count = count($row);
for ($i = 0; $i < $count; $i++)
if ($row[$i] === '' || $row[$i] === 'NULL')
$empty_count++;
$com = ((int)(100 * (1 - $empty_count/($count - 1))));
if ($com > 50) {
echo "<span class='f_left width_autor textLeft GreenFont padding_8R'>".((int)(100 * (1 - $empty_count/($count - 1))))."%</span>";
} else {
echo "".((int)(100 * (1 - $empty_count/($count - 1))))."%";
}
}
}
?>
但是当我尝试运行代码,它总是给8%完成,即使我尝试完成一些配置文件,以使其60%,它没有它如果我完成配置文件,只需要提供8%或100%的配置文件
现在我该如何编写查询以使其按预期工作。 谢谢。
我不亲的PDO,但我看,要覆盖'$ completeProfile'变量,所以你会得到只有最后querys结果时' $ completeProfile-> execute()'发生。 – vaso123 2014-10-20 08:27:21
所以你认为我应该改变每个查询的名称,并执行每一个'$ completeProfile1-> execute()'和'$ completeProfile2-> execute()'我是否理解你 – Mikky 2014-10-20 08:31:30