0
Hello, my friends.
I have 3 tables in my mysqli bank to record access to a particular location:
visitor, whose data will always be filled in.
corporate, whose data will be filled in only if the visitor represents a company.
vehicle, whose details will be filled out if the visitor comes by car.
When making a search to return all results, I use the following query:
SELECT *
FROM `visitante`
LEFT JOIN `corporativo` ON `corporativo`.`id_visitante` = `visitante`.`id_visitante`
LEFT JOIN `veiculo` ON `veiculo`.`id_visitante` = `visitante`.`id_visitante`
WHERE `visitante`.`entrada` LIKE '%$data%' OR `visitante`.`status` LIKE '%Aberto%'
GROUP BY `visitante`.`id_visitante`
ORDER BY `visitante`.`entrada`;
What happens is that in the logs where I have no corporate visitor data or vehicle data, it returns my visitor id as NULL.
I think it’s some PHP problem because when doing this query in phpmyadmin, it returns all the data normally.
Does anyone have any suggestions???
Thank you.
From the format of your query it appears that you are not using [Prepared Statements] (https://secure.php.net/manual/en/mysqli.quickstart.prepared-statements.php). Maybe it’s some value in
$data
that is causing the problem?– Ricardo Moraleida
@I really don’t know about these preparations. However I had a problem with this query in the system I did at hand and now I’m learning a little bit of Codeigniter and I’m rebuilding it in CI. I believe that the functions of the IC already incorporate these procedures. However, I removed all conditions and only left the left Join for the other tables and even then when I do not have the records of these tables, my id returns null. When other tables are filled in, id comes normal.
– user3520691
If I do the same query by giving a select visitor.id_visitor, all results come normal. Only when I give a select * do I have the problem.
– user3520691
There are 3 different id_visitors, the ones from the non-responsive table come null even. are you sure you’re looking at the right one? It would be good to remove that * from the query and use the fields correctly in the SELECT table.field or SELECT alias format., ....
– Bacco
There are many fields. But really the problem was the name. I simply changed the name in the database to visitnte_id and it returned me correctly. I do not know why the query does not return me what I want, even saying I was visitor.id_visitor. Thanks.
– user3520691