我想计算行数并在我的视图中显示链接..当用户点击链接将转到特定网址的数字时..
这是我的模特:
function getrequirementsdate($date1,$date2)
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$this->db->where('created_date >=', $date1);
$this->db->where('created_date <=', $date2);
$query = $this->db->get();
//echo $this->db->last_query();
$rowcount = $query->num_rows();
//echo $rowcount;
return $query->result();
}
另一种模式:
function getrequirements()
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result();
}
这是我的控制器:
public function view_requirements_bydate($date1="",$date2="")
{
$data["msg"]="";
$data = array(
'total_item' => $this->ReportModel->getrequirementsdate($date1,$date2)
);
if($date1=='' && $date2=='' )
{
$data['view_requirements'] = $this->ReportModel->getrequirements();
}
else
{
$data['view_requirements'] = $this->ReportModel->getrequirementsdate($date1,$date2);
}
$this->load->view('Reports/view_requirements_bydate',$data);
}
查看:(此处显示计数编号)..
<body>
<h4>No of Requirements:</h4>
</body>
这是我的表格代码:
<div class="box-body">
<table id="" class="table table-bordered table-hover">
<thead>
<tr>
<th>Role Name</th>
<th>Vacancies</th>
<th>Experience</th>
<th>Job Description</th>
<th>Hiring Contact Number</th>
<th>Hiring Contact Name</th>
<th>Date</th>
</tr>
</thead>
<?php
foreach ($view_requirements as $idata)
{
?>
<tbody>
<tr id="domain<?php echo $idata->req_id;?>">
<td><?php echo $idata->role_name;?></td>
<td><?php echo $idata->vacancies;?></td>
<td><?php echo $idata->experience;?></td>
<td><?php echo $idata->jd;?></td>
<td><?php echo $idata->hiring_contact_number;?></td>
<td><?php echo $idata->hiring_contact_name;?></td>
<td><?php echo $idata->created_date;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
任何人都可以帮我解决这个问题 谢谢..
答案 0 :(得分:1)
模型1
function getrequirementsdate($date1,$date2)
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$this->db->where('created_date >=', $date1);
$this->db->where('created_date <=', $date2);
$query = $this->db->get();
return $query->result_array();
}
模型2
function getrequirements()
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$query = $this->db->get();
return $query->result_array();
}
<强>控制器强>
function view_requirements_bydate($date1="",$date2="")
{
$data["msg"]="";
if($date1 =='' && $date2 =='' )
{
$data['view_requirements'] = $this->ReportModel->getrequirements();
}
else
{
$result_array = $this->ReportModel->getrequirementsdate($date1,$date2);
$data['total_item'] = count($result_array);
$data['view_requirements'] = $this->ReportModel->getrequirementsdate($date1,$date2);
}
$this->load->view('Reports/view_requirements_bydate',$data);
}
查看强>
<body>
<h4>echo $total_item;</h4> // or print_r($total_item)
</body>
答案 1 :(得分:0)
在您的视图页面中添加
<body>
<h4>No of Requirements:<a href="your url here"><?php echo count($data);?></a></h4>
</body>
答案 2 :(得分:0)
<body>
<h4>No of Requirements:<a href="your url here"><?php echo $view_requirements?></a></h4>
</body>
尝试..
答案 3 :(得分:0)
尝试以下代码:
<强>模型强>
function getrequirementsdate($date1,$date2)
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$this->db->where('created_date >=', $date1);
$this->db->where('created_date <=', $date2);
$query = $this->db->get();
$rowcount = $query->num_rows();
return $rowcount;
}
function getrequirements()
{
$this->db->select('*');
$this->db->from('requirements');
$this->db->join('role','role.role_id=requirements.role_id');
$query = $this->db->get();
// echo $this->db->last_query();
$rowcount = $query->num_rows();
return $rowcount;
}
<强>控制器强>
public function view_requirements_bydate($date1="",$date2="")
{
$data["msg"]="";
$data["total_item"] = $this->ReportModel->getrequirementsdate($date1,$date2);
if($date1=='' && $date2=='' )
{
$data['view_requirements'] = $this->ReportModel->getrequirements();
}
else
{
$data['view_requirements'] = $this->ReportModel->getrequirementsdate($date1,$date2);
}
$this->load->view('Reports/view_requirements_bydate',$data);
}
查看强>
<body>
<h4>No of Requirements:</h4>
<a href="REDIRECT_URL"><?php echo $view_requirements; ?></a>
</body>