0
<?php
error_reporting(E_ERROR);
session_start();
$var_quant = $_SESSION['quantvend'];
$var_varejo_atacado = $_GET['varejo-atacado'];
$con = mysql_connect("localhost","root","");
mysql_select_db("edutricot");
for($i = 1; $i<=$var_quant ; $i++){
$var_nome{$i} = $_GET['txtcod'.$i];
$var_quantvend{$i} = $_GET['txtquant'.$i];
$var_varejo_atacado = $_GET['varejo-atacado'];
echo $var_varejo_atacado;
echo $var_nome{$i};
echo $var_quantvend{$i};
echo "<br>";
$query = "SELECT $var_varejo_atacado FROM estoque where nome = $var_nome.$i";
$dados = mysql_query($query,$con);
while($row=mysql_fetch_array($dados,MYSQL_ASSOC)){
$var_valor{$i} = $row["$var_varejo_atacado"];
$_GLOBALS['valor'.$i] = $var_valor{$i};
}
$_GLOBALS['prodquant'.$i] = $var_quantvend{$i};
$var_valor{$i} = $_GLOBALS['valor'.$i];
}
?>
I’m new to dealing with php and needed someone to explain to me how I can concatenate two variables to put in Mysql query.
$query = "SELECT $var_varejo_atacado FROM estoque where nome = $var_nome.$i";
I am trying to concatenate using the . but always from the error, would have some way to make this concatenation?
$var_nome{$i} = $_GET['txtcod'.$i];
This is the line where I’m trying to get the information, but I realized that the $var_nome{$i}
not concatenating the way I expected, not creating for example $var_nome1
, $var_nome2
etc..
I think you should review the code and use array instead of continuing with the line of reasoning of using sequential variables, both in HTML and PHP.
– Benilson
Use array.
– Augusto Vasques