3
In the example:
SELECT * FROM exemplo WHERE ID in(2, 3, 4)
He brings if he has these ID
at the bank.
How to mount a query which places this condition only if the array in PHP have elements?
PHP:
$id= implode(', ', $_GET['id']);
$nome= implode(', ', $_GET['nome']);
$cidade= implode(', ', $_GET['cidade']);
$query = mysql_query("SELECT * FROM EXEMPLO WHERE id IN($id) AND nome IN($nome) AND cidade IN($cidade)");
//Se tiver de acordo com a condição traz a linha dentro da condição, se não traz todas as linhas.
I tried it like this, but I don’t know if it’s right;
$id= "(id='".implode("' OR id='", $_GET['id'])."') AND";
$nome= "(nome='".implode("' OR nome='", $_GET['nome'])."') AND";
$cidade= "(cidade='".implode("' OR cidade='", $_GET['cidade'])."')";
$query = mysql_query("SELECT * FROM EXEMPLO WHERE $id $nome $cidade");
The time you finish changing the problem, you warn me and I try to answer correctly. Every time I hit the answer you change something.
– Maniero
The
")
in the last row.– Jorge B.
Yes I forgot to type here rs..
– Romario Pires
Face this implode, it will only work if you have an array with the Ids in that $_GET['id']; type $get_data = array(1,2,3,4,5,6); implode(', ', $get_data);
– Ivan Ferrer
Yes I use various inputs with name="id[]", this causes me to send via get an array.
– Romario Pires