Mysql Cross Query

Asked

Viewed 60 times

0

I’m not sure how much to express myself more than I need is how I can do a normal and reversed query. Below I have two fields one of origin and the other of destination. I need to make a

       $origem = $_post["origem"];
       $destino = $_post["destino"];

       SELECT * FROM produtos
       where  origem LIKE ?  AND  destino LIKE ?
       $sql3->bind_param("sssiisssss",  $origem,$destino);

Plus what I need and that she accepts the vice verse

inserir a descrição da imagem aqui

Campos
<input type="text" name="Origem"> 
<input type="text" name="Destino"> 

Base Origem e Destinos
+----+--------+---------+------+---------+
| id | Origem | Destino | nome |  Valor  |
| 01 |  Rio   | Campos  | R C  | 100,00  |
| 02 |Niteroi |  Rio    | N R  | 200,00  |
| 03 | Macaé  | Campos  | M C  | 300,00  |
| 04 | Centro | Barra   | C B  | 400,00  |

1 answer

2

To query below returns what you need:

SELECT * FROM produtos
WHERE  (origem LIKE ?  OR  destino LIKE ?) AND (origem LIKE ?  OR  destino LIKE ?)

The passing of the parameters would look like this:

$sql3->bind_param("ssss", $origem, $destino, $destino, $origem);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.