In my model, I want to filter my query with a GET parameter, but when I put into the “where”, the value is lost. I also tried assig the value to any variable and I had no problem.
Why the value is lost?
function list_items($limit = NULL, $offset = NULL, $col = '', $order = 'ciclo desc', $just_count = FALSE)
{
$info = '';
if(isset($_GET['id_info']))
$info = $_GET['id_info'];
echo "info=".$info."\n";
$c = '1';
$array = array('id_info' => $info, 'ciclo' => $c);
var_dump($array);
$this->db->where($array);
$this->db->select('id, id_info, ciclo, presion_arterial, frecuencia_cardiaca, frecuencia_respiratoria, temperatura, talla, peso, imc, superficie_corporal', FALSE);
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
$this->debug_query();
return $data;
}
The result in the browser is:
info= array(2) { ["id_info"]=> string(0) "" ["ciclo"]=> string(1) "1" } SELECT id, id_info, ciclo, presion_arterial, frecuencia_cardiaca, frecuencia_respiratoria, temperatura, talla, peso, imc, superficie_corporal FROM (`signos_vitales`) WHERE `id_info` = '' AND `ciclo` = '1' ORDER BY `id_info` asc LIMIT 50
View the code is:
info=1
array(2) {
["id_info"]=>
string(1) "1"
["ciclo"]=>
string(1) "1"
}
SELECT COUNT(*) AS `numrows`
FROM (`signos_vitales`)
WHERE `id_info` = '1'
AND `ciclo` = '1'
Comments
Thanks
Maybe add a $this->db->where() and then pull the data directly?
I have my URL like this:
http://../fuel/signos_vitales/?ciclo=1&id_info=1
function list_items($limit = NULL, $offset = NULL, $col = '', $order = 'ciclo desc', $just_count = FALSE) {
$info = '';
$ciclo = '';
if(isset($_GET['id_info']))
$info = $_GET['id_info'];
if(isset($_GET['ciclo']))
$ciclo = $_GET['ciclo'];
$qry = 'select id, id_info, ciclo, presion_arterial, frecuencia_cardiaca, frecuencia_respiratoria, temperatura, talla, peso, imc, superficie_corporal from signos_vitales where id_info='.$info.' and ciclo='.$ciclo;
$this->db->query($qry);
$data = parent::list_items($limit, $offset, $col, $order, $just_count);
$this->debug_query();
return $data;
}
I verify that the variables $_GET have values, applying "echo", then apply in my query
But the result is the same when debug:
You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near 'and ciclo=' at line 1
select id, id_info, ciclo, presion_arterial, frecuencia_cardiaca, frecuencia_respiratoria, temperatura, talla, peso, imc, superficie_corporal from signos_vitales where id_info= and ciclo=
I don't know why lost the values of variables when execute query.
Thanks
https://drive.google.com/file/d/0Bzij4lOEOgALZG5XTGlfdElmZkE/view