我在codeigniter中遇到了这个错误:
未定义的属性:stdClass :: $ total_dependents
我的SQL查询中的位置是:
COUNT(distinct `employee_children`.`ID` )+COUNT(distinct `employee_dependents`.`ID` ) as total_dependents
此SQL查询是正确的。因为我已经在MySQL Linux中尝试过了。
在我看来:
<?php if ($search_result!=""){ ?>
<?php foreach($search_result as $row): ?>
<tr>
<td style="vertical-align: middle;"><?php echo $row['employee_id'];?></td>
<td style="vertical-align: middle;"><?php echo $row['company'];?></td>
<td style="vertical-align: middle;"><?php echo $row['full_name'];?></td>
<td style="vertical-align: middle;">N/A</td>
<td style="vertical-align: middle;">N/A</td>
<td style="vertical-align: middle;">N/A</td>
<td style="vertical-align: middle;">N/A</td>
<td style="vertical-align: middle;">N/A</td>
<td style="vertical-align: middle;"><?php echo $row['job_title'];?></td>
<td style="vertical-align: middle;"><?php echo $row['department'];?></td>
<td style="vertical-align: middle;"><?php echo $row['company_email'];?></td>
<td style="vertical-align: middle;"><?php echo ($row['mobile']!=""?$row['mobile']:"N/A");?></td>
<td style="vertical-align: middle;">
<?php if($row['gender']=="Male"){echo $row['gender']."<p style='visibility:hidden;position:fixed'>boy</p>";}
else if($row['gender']=="Female"){echo $row['gender']."<p style='visibility:hidden;position:fixed'>girl</p>";}
else{echo "";}?></td>
<td style="vertical-align: middle;"><?php echo $row['civil_status']; ?>
<?php //echo ($row['total_dependents']!=0?" - ".$row['total_dependents']:""); ?></td>
<td style="vertical-align: middle;"><?php //echo ($row['hmo_enrollment']!=""?"Yes":"No");?></td>
<td style="vertical-align: middle;"><?php echo ($row['sss']!=""?$row['sss']:"N/A");?></td>
<td style="vertical-align: middle;"><?php echo ($row['phil']!=""?$row['phil']:"N/A");?></td>
<td style="vertical-align: middle;"><?php echo ($row['pagibig']!=""?$row['pagibig']:"N/A");?></td>
<td style="vertical-align: middle;"><?php echo ($row['tin']!=""?$row['tin']:"N/A");?></td>
<td style="vertical-align: middle;"><?php echo date("F j, Y",strtotime($row['birth_date']));?></td>
<td style="vertical-align: middle;"><?php echo ($row['home_address']!=""?$row['home_address']:"N/A");?></td>
<td style="vertical-align: middle;"><?php echo $row['emergency_name']."<br>".$row['emergency_mobile'];?></td>
<?php $id = $row['employee_id'];?>
<td style="vertical-align:middle;"><img src="<?php echo base_url(); ?>images/information.png" width="50" height="50" title="Show Information" onclick="redirect('<?php echo $id; ?>');" style="cursor:pointer"></td>
<td style="vertical-align:middle;"><img src="<?php echo base_url(); ?>images/print.png" title="Print Employee CV SMS FORMAT" onclick="printSMS('<?php echo $id; ?>');" style="cursor:pointer;width:30px; height:30px;"></td>
<td style="vertical-align:middle;"><img src="<?php echo base_url(); ?>images/print.png" title="Print Employee CV OUTSOURCE FORMAT" onclick="printCV('<?php echo $id; ?>');" style="cursor:pointer;width:30px; height:30px;"></td>
<!--td style="vertical-align:middle;"><img data-toggle="modal" class="delete-data" href="#delete" style="cursor:pointer" height="15" width="15" src="<?php echo base_url(); ?>images/remove.gif"></td-->
</tr>
<?php $ctr++; endforeach; } ?>
<div id="found" style="margin-top:-25px;margin-left:3px;position:absolute;font-size:11px;"><b><?php echo $ctr; ?> record/s found.</b></div>
<?php endif; ?>
完整查询:
SELECT *, CONCAT(`home_streetno`, ' ', `home_subvillage`, ' ', `home_brgy`, ' ', `home_city`) AS `home_address`,
COUNT(distinct `employee_children`.`ID` )+COUNT(distinct `employee_dependents`.`ID` ) as `total_dependents`,
`employee_emergency_contact`.`name` as `emergency_name`, `employee_emergency_contact`.`mobile_number` as `emergency_mobile`
FROM (`employee`)
LEFT JOIN `employee_health_info` ON `employee`.`employee_id` = `employee_health_info`.`emp_id`
LEFT JOIN `employee_dependents` ON `employee_dependents`.`emp_id` = `employee`.`employee_id`
LEFT JOIN `employee_emergency_contact` ON `employee`.`employee_id` = `employee_emergency_contact`.`emp_id`
LEFT JOIN `employee_children` ON `employee`.`employee_id` = `employee_children`.`emp_id`
LEFT JOIN `employee_contact` ON `employee`.`employee_id` = `employee_contact`.`emp_id`
LEFT JOIN `employee_government_registration` ON `employee`.`employee_id` = `employee_government_registration`.`emp_id`
LEFT JOIN `employee_employment_status` ON `employee`.`employee_id` = `employee_employment_status`.`emp_id`
LEFT JOIN `department` ON `department`.`ID` = `employee_employment_status`.`department`
LEFT JOIN `job_title` ON `job_title`.`ID` = `employee_employment_status`.`job_title`
WHERE (employee_id REGEXP(@search)
OR first_name REGEXP(@search)
OR last_name REGEXP(@search)
OR middle_name REGEXP(@search)
OR title REGEXP(@search)
OR company_sms REGEXP(@search)
OR department.department REGEXP(@search)
OR home_streetno REGEXP(@search)
OR home_subvillage REGEXP(@search)
OR home_brgy REGEXP(@search)
OR home_city REGEXP(@search)
OR company_email REGEXP(@search)
OR last_name REGEXP(@search)
OR gender REGEXP(@search)
OR employee_contact.mobile_number REGEXP(@search)
OR civil_status REGEXP(@search)
OR sss_number REGEXP(@search)
OR philhealth_number REGEXP(@search)
OR tin_number REGEXP(@search)
OR pagibig_number REGEXP(@search)
OR employee.birth_date REGEXP(@search)
OR employee_emergency_contact.name REGEXP(@search)
OR philhealth_number REGEXP(@search)
OR employee_emergency_contact.mobile_number REGEXP(@search))
and `employee`.`employee_id` NOT IN ('1990') group by `employee_id`
模特中的
if ($query->num_rows > 0){
foreach ($query->result() as $row)
{
$data[] = array(
'employee_id' => $row->employee_id,
'full_name' => $row->first_name.' '.$row->middle_name.' '.$row->last_name,
'job_title' => $row->title,
'company' => $row->company_sms,
'department' => $row->department,
'home_address' => $row->home_address,
'company_email' => $row->company_email,
'gender' => $row->gender,
'mobile' => $row->mobile_number,
'civil_status' => $row->civil_status,
'sss' => $row->sss_number,
'phil' => $row->philhealth_number,
'tin' => $row->tin_number,
'pagibig' => $row->pagibig_number,
'birth_date' => $row->birth_date,
'emergency_name' => $row->emergency_name,
'emergency_mobile' => $row->emergency_mobile
);
}
}
else
$data = "";
return $data;