Welcome Guest, Not a member yet? Register   Sign In
codeigniter
#1

hi,can anybody help me to get this done?
controller
function reports_data($serial,$opt=1)
{
$this->form_validation->set_rules('cycle_timestamp', 'cycle_timestamp', 'xss_clean|max_length[20]');
$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
$this->load->view('dashboard/dashboard_header_view',$this->data);
$data['report_data'] = $this->dashboard_model->get_cycledata($serial,$opt);
$this->load->view('dashboard/dashboard_report_data',$data);
$this->load->view('dashboard/dashboard_footer_view');
}
model
function get_cycledata($serial,$opt=1)
{
$options=array();
$option[1] = "cycle_18_INT";//Percent Full
$option[2] = "cycle_03_INT";//Pressure
$option[3] = "cycle_06_INT";//Current
$option[4] = "cycle_08_INT";//Voltage
$option[5] = "cycle_17_INT";//State of Charge

$cols = "`cycle_timestamp`,`".$option["$opt"]."`";
$field = $option["$opt"];

$this->db->select($cols);
$this->db->from('cycles');
$this->db->where('cycle_serial', $serial);
$this->db->order_by("cycle_timestamp","asc");
$query = $this->db->get();
If($opt==3 or $opt==4){
$chartdata = "[";
if($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
$chartdata=$chartdata."[".$row['cycle_timestamp']."000,".($row["$field"]/10)."],";
}
$chartdata = substr($chartdata, 0, -1);
$chartdata = $chartdata."]";

}
return $chartdata;}
else{
$chartdata = "[";
if($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
$chartdata = $chartdata."[".$row['cycle_timestamp']."000,".($row["$field"])."],";
}
$chartdata = substr($chartdata, 0, -1);
$chartdata = $chartdata."]";

}
return $chartdata;

}


}
view
<div class="table-reports">

<table>


<tr>
<th>Date</th>
<th>Time</th>
<th>Percent Full</th>
<th>Pressure</th>
<th>Current</th>
<th>Voltage</th>
<th>State of Charge</th>



</tr>
<?php foreach ($report_data as $row)

{

echo "<tr>";
echo "<td>".date("m/d/Y",$row->cycle_timestamp)."</td>";
echo "<td>".date("g:i A",$row->cycle_timestamp)."</td>";

echo "<td>".anchor('dashboard/reports_data/<?php echo $serial; ?>/1', $row->cycle_18_INT)."</td>";
echo "<td>".anchor('dashboard/reports_data/<?php echo $serial; ?>/2', $row->cycle_03_INT)."</td>";
echo "<td>".anchor('dashboard/reports_data/<?php echo $serial; ?>/3', $row->cycle_06_INT)."</td>";
echo "<td>".anchor('dashboard/reports_data/<?php echo $serial; ?>/4', $row->cycle_08_INT)."</td>";
echo "<td>".anchor('dashboard/reports_data/<?php echo $serial; ?>/5', $row->cycle_17_INT)."</td>";
echo "</tr>";

}

?>
<tr><td colspan="7"></td></tr>
</table>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB