1
I need to find a result in the database, and show it on the cart screen. I am using codeigniter, already created the model and controller and I am calling in the view, but the result does not come.
The value I look for is’s' or 'n' in the table 'ga845_client' column 'wholesaler'.
I appreciate the help.
Controller (shopping cart)
public function exibeAtacadista(){
//busca os arquivo na tabela cliente
$this->load->model('carrinho_model');
$atacadista = $this->carrinho_model->getAtacadista($data);
}
Model (cart_model)
public function getAtacadista($data){
$this->db->flush_cache();
$sql = "SELECT * FROM `ga845_cliente` WHERE atacadista = 's' = ".$data['atacadista']." ";
$query = $this->db->query($sql);
print_r($query); die();
return $query->result();
}
View (cart)
I’m calling it that.
echo 'teste:' .$atacadista;
Does the query return any list? If yes, it could show how the data comes?
– Edward Ramos
Returns nothing, goes blank, but in the bank has the value’s'
– Everton Thomazi
I use different commands to search the model, take a look and see if it helps you.
function getSetor($data) {
 $this->db->flush_cache();

 $sql = "
 SELECT u.id_setor, s.nome_setor FROM usuarios u
 LEFT JOIN setores s ON s.id_setor = u.id_setor
 WHERE u.id_usuarios = ".$data['id_usuario']."
 ";

 $query = $this->db->query($sql);
 return $query->result();
 }
– Edward Ramos
Worse that didn’t happen either, as I’m learning to deal with codeigniter, I still have a hard time understanding where the mistake might be.
– Everton Thomazi
You tested the query in the database?
– Edward Ramos
Sorry ignorance, I’m in the basics of PHP yet, how do I do this?
– Everton Thomazi
PHP runs on a server, usually the staff uses Xampp’s phpAdmin, that would be?
– Edward Ramos
All right, that’s right
– Everton Thomazi
By accessing phpAdmin, log into your database where you have the
tabela ga845_cliente
, when you click on this table, the data will appear. Above the data there are tabs, one of them has the SQL name, click on it. In this part, you paste the codeSELECT * FROM
ga845_clientWHERE
wholesaler= 'S'
and rotate to see the result.– Edward Ramos
Right, he showed the two results I have with the S parameter'
– Everton Thomazi
Blz, so , in your controller you need to give a
print_r($this->carrinho_model->getAtacadista($this->session->userdata('atacadista'));) die();
– Edward Ramos
And see if printa in the browser console(F12 - Network) the list
– Edward Ramos
I put it inside the controller I mentioned above, and it did not return anything on the console
– Everton Thomazi
Jeez... What if you put the print_r in the model? It returns something? Where is it
return $query
putsprint_r($query); die();
– Edward Ramos
Also nothing, to see if I’m not doing wrong, pasted inside the model file after the line "Return $query;"
– Everton Thomazi
Put this command before Return, and see if it prints something, as it is not possible that it will not print....
– Edward Ramos
I put and also showed nothing, I’m going to my view page that calls this model and controller, right?
– Everton Thomazi
That’s right, in your view you call this function and should print something on the console... And the query is correct, so much so that in the database it does the search and returns... How is your configuration, in php, to connect in the database? The path would be Application/config/database.php and see the configuration in the $db variable[]
– Edward Ramos
Worse than not calling anything, the configuration is right, because it looks for the other values of other tables. What should I call it in the view? Just to confirm
– Everton Thomazi
I use Ajax to call, I think it won’t fit here in the comment, so create an answer to show you.
– Edward Ramos