4
It is very common to find on websites a search that returns records from different tables.
I need to implement on my site a search that returns produtos
and usuários
(profile) registered on the site. The result should be to mix, however the link to the same will be different, ex: site.com/perfil/id
and site.com/produto/id
.
I’m gonna need two querys? Or just with a consultation with you that result?
I won’t be able to use JOIN
since my charts are unrelated.
I hope I’ve been clear.
I would say that it was better to do separate searches and show in the table of results (if it is a table) the results with the proper link.
– Jorge B.
Jorge, there is no table results, the same is the return (write on screen) of the query of the two tables.
– Dagobe
I was talking about a
table
but can be anything else.– Jorge B.
That way the result won’t come mixed up, right? I will first have the list of all products found and then all users found?
– Dagobe
Yeah, that’s pretty much it.
– Jorge B.
Your tables are the same, with the same fields?
produto.id, produto.nome
,usuario.id, usuario.nome
...? If so, you can useUNION ALL
– Papa Charlie
@Papacharlie but this won’t screw up? Then how does he know which search links to which table?
– Jorge B.
@Jorgeb. I don’t think so, I would: query-1
concat("user") as 'tipo'
, query-2concat("product") as 'tipo'
, so we have the table type reference.– Papa Charlie
@Papacharlie makes an answer.
– Jorge B.
@Jorgeb., but it depends on the structure of his table. But I will elaborate a simple answer here.
– Papa Charlie