Is it possible to store an select value into an variable? in codeigniter. Something like this:
$this->db->select_max('Datum');
$this->db->from('Uren');
$this->db->join('Project','Project.idProject = Uren.idProject');
$test123 = $this->db->get();
So that i get the value of the select_max
into the variable $test123
I think you need to do something like this.
$this->db->select_max('Uren.Datum');
$test = $this->db->get('table_name');
if ($test) {
$this->db->select('fields');
$this->db->group_by('Project.idProject');
$this->db->get('table_name');
}
these will be two separate quires.
try
$this->db->select_max('field_name');
$check_query = $this->db->get('table_name');
if ($check_query->num_rows() > 0) {
$max = $check_query->result();
if(!empty($max[0]->field_name)) {
}
}
for more :- https://www.codeigniter.com/userguide2/database/active_record.html
The proprer way, then $max will contain the max of your request, or FALSE if request is not valid :
$query = $this->db->select_max('Uren.Datum', 'max_Datum')->get('your_table');
$max = $query ? $query->row()->max_Datum : FALSE;
This is the answer that worked to my question. Hope it will help someone else too
$this->db->select_max('Datum');
$this->db->from('Uren');
$this->db->join('Project','Project.idProject = Uren.idProject');
if ($idKlant > 0){
$this->db->where('idKlant', $idKlant);}
$datumstart = $this->db->get();
foreach ($datumstart->result() as $row)
{
$datastart = $row->Datum;
}