我在codeigniter中有这个数据库数组,我想将它传递给javascript函数。可能吗?
模型:
public function show_employment_skills($P1)
{
$this->db->select('*');
$this->db->from('employee_skills');
$this->db->where('emp_id', $P1);
$this->db->order_by('ID', 'desc');
$query = $this->db->get();
if($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = array(
'id' => $row->ID,
'emp_id' => $row->emp_id,
'skills' => $row->skills
);
}
}
else
{
$data = "";
}
return $data;
}
在得到 $data 之后(那是一个 DB 数组,对吗?)
这是我的控制器
public function swoosh_employment_skills()
{
$P1 = $this->session->userdata('id');
$set['record_skills'] = $this->emp->show_employment_skills($P1);
$this->load->view('swoosh_template/employee/employmentskills',$set);
}
$set['record_skills'] 是来自数据库的数组..
现在这是我的观点:
<?php if ($record_skills != "") } ?>
<table class="table table-bordered">
<tr>
<th>Skills</th>
<th style='width:50px;'>Alert it!</th>
</tr>
<?php foreach ($record_skills as $row): ?>
<tr>
<td class="skills"><?php echo $row['skills'];?></td>
<td><img src=alert_it.png onclick="show(db array that i should put. but how?);"</td>
</tr>
</table>
这是javascript
function show(array){
//in here i should alert all the values of arrays. ..
}