我正在为一个网站的搜索栏创建一个页面,但另一个我不断收到无效的参数错误。希望所需的一切都在下面。我正在使用codeigniter。请帮忙。感谢。
//不起作用//
private function getUsers () {
$search = $this->input->post('search');
if($search && filter_var($search, FILTER_VALIDATE_EMAIL)) {
$where = 'WHERE source_adusers.ad_Email="'.$search.'"';
} else if ($search) {
$where = "WHERE source_adusers.ad_account='".$search."'";
} else if (!$search) {
$where = '';
}
$query = $this->db->query('SELECT *, COUNT(rollout_systems.EAM_USER) as systems FROM source_adusers
LEFT JOIN rollout_systems ON rollout_systems.EAM_User = source_adusers.ad_account '.$where.' GROUP BY source_adusers.ad_account LIMIT 0,50');
$users = null;
foreach ($query->result() as $row) {
$data['account'] = $row->ad_account;
$data['email'] = $row->ad_Email;
$data['name'] = $row->ad_DispName;
$data['systems'] = $row->systems;
$users[] = $data;
}
if(isset($this->data['users'])) {
$this->data['users'] = $users;
} else {
$this->data['users'] = $users;
}
}
//是否工作//
private function getSystems () {
$search = $this->input->post('search');
if ($search) {
$where = 'WHERE disc_systempool.ad_name="'.$search.'"';
} else {
$where = '';
}
$query = $this->db->query('SELECT *, COUNT(rollout_systems.sys_name) as scopes FROM disc_systempool LEFT JOIN rollout_systems
ON rollout_systems.sys_name=disc_systempool.ad_name '.$where.' GROUP BY disc_systempool.ad_name LIMIT 0,50');
foreach ($query->result() as $row) {
$data['model'] = $row->eam_Model;
$data['account'] = $row->ad_name;
$data['city'] = $row->eam_City;
$data['scopes'] = $row->scopes;
$data['search'] = $this->input->post('search');
$systems[] = $data;
}
if(isset($this->data['systems'])) {
$this->data['systems'] = $systems;
} else {
$this->data['systems'] = $systems;
}
}
//我收到错误//
<tbody>
<? foreach ($users as $user) { ?> <---- Line 18
<tr>
<td class="center"><?=$user['account']?></td>
<td><?=$user['name']?></td>
<td><?=$user['email']?></td>
<td class="center"><?=$user['systems']?></td>
<td class="center"><a href="#">View Details</a></td>
</tr>
<? } ?>
</tbody>
//错误//
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: headquarters/users.php
Line Number: 18
答案 0 :(得分:0)
它表明了正确的事情。我解决了这个问题。我误解了雇用我的人要求我做什么。他说搜索帐户名称。我是搜索显示名称,一直给我错误。
答案 1 :(得分:-1)
尝试在视图中制作var_dump($data);
。如果是空的。只需将其打印出来,即可在控制器中执行相同的操作。如果您在$data
数组中看到数据。确保您将$data
数组一起发送到视图$this->load->view("view",$data);
除此之外,我可能想知道为什么要对控制器内部的行进行操作,而不是仅仅在视图中使用对象
return $query->result();
在视图中
foreach($users as $user) { print $user->account; }
希望你弄明白。 最好的祝福 纳斯