0
Hello guys I’m trying to make a query using vector, but as far as I’ve learned the sql command does not hold the vector the way I’m doing so my result is empty variable.
$idcliente=$_SESSION['id_cliente'];
$loja=$_POST['loja'];
$quant[0]=$_POST['quant'];
$quant[1]=$_POST['quant2'];
$quant[2]=$_POST['quant3'];
$produtos[0]=$_POST['produto'];
$produtos[1]=$_POST['produto2'];
$produtos[2]=$_POST['produto3'];
$tipo=$_POST['ttipo'];
$acrescimo=$_POST['acrescimo'];
$pedido=$_POST['pedido'];
$entrega=$_POST['entrega'];
$montagem=$_POST['montagem'];
$tsmg=$_POST['tsmg'];
$x=mysqli_query($conn,"select*from produtos where descricao='$produtos'");
$prt=mysqli_fetch_array($x);
$idproduto[]=$prt['id_produto'];
$codigo[]=$prt['codigo'];
$descricao[]=$prt['descricao']."";
$cor[]=$prt['cores'];
$marca[]=$prt['marca'];
$valorm[]=$prt['valormontagem'];
print_r($descricao);
Here is the excerpt that sends the data to the above commands.
<td><input list='produtos' name='produto'/>
<datalist id='produtos'><?php
$sql= mysqli_query($conn,"select descricao from produtos order by descricao");
while ($resp = mysqli_fetch_array($sql)) {
$group=$resp['descricao'];
echo "
<option value='$group','$cor'>";
}
?> </datalist></td>
I made with 2 products as a test.
print_r($produtos);
Array ( [0] => BERCO CHANTILY [1] => BERCO ALEGRIA [2] => )
print_r($descricao);
Array ( [0] => )
Where is the variable
$produto
? What is she?– Miguel
It comes from a form. In this field it is reading a table and displaying for selection. I gave a
print_r
and in that part is exhibiting perfectly.– Danilo Araujo
That is to say
$produto
is an array right? Please put the array format to help you– Miguel
I’m a student, so I’m sorry about that stupid question. Apart from the content I’ve already shown I don’t know how to show you the format of the array, if you can give me a hint I would be very grateful.
– Danilo Araujo
You can put exactly the impression of
print_r($produtos)
– Miguel
Done, edited to facilitate the organization.
– Danilo Araujo
And he wants to go for ex: the products whose descriptions are BERCO CHANTILY and BERCO ALEGRIA right?
– Miguel
Right friend exactly that.
– Danilo Araujo
See if this below will work
– Miguel
I withdrew the answer, since it wasn’t helping, basically corrected
foreach($produtos as $prod) {
 $query .= " descricao='$prod' OR";
}
$query = rtrim($query, ' OR');
, ofAND
forOR
. If I can’t do it I don’t see what else– Miguel
Your answer was right @Miguel. Some detail I didn’t see either that didn’t work out.
– Andrei Coelho
Exactly did the tests and worked perfectly thanks to all who helped me learned something new and I am very grateful.
– Danilo Araujo
'Cause I tested it here and it was also @Andreicoelho, but it was being so bad accepted that I took it out thinking I was making a huge mistake
– Miguel
Relax when you corrected your remarks worked perfect.
– Danilo Araujo
No problem. Entertaining Daniloaraujo should accept @Andreicoelho’s answer that works well and is a solution to the problem
– Miguel
Actually @Miguel your answer is more correct. I would like those who have denied it to make some observation.
– Andrei Coelho
Thanks @Andreicoelho. Maybe they were negative at first, I made some syntax errors by mistake
– Miguel
Got it, can you. =)
– Andrei Coelho