Query mysql according to Array unserialize

1

In this select down how can I make it just return the rows with ids that are in this variable ($ range) this variable is returning data from the various database ids

// estou utlizando a função unserialize
$range = unserialize ($linha["range_ids"]);     

$sql = "SELECT a.*, f.*,e.*,u.*,p.*, SUM(valor) AS 'soma'  FROM a_finan AS f 

LEFT JOIN agenda_saidas AS a
ON a.id_saida = f.id_saida
LEFT JOIN empresas AS e
ON e.id_empresa = f.id_empresa
LEFT JOIN usuarios AS u
ON u.id_user = f.user_soli
LEFT JOIN passageiros AS p
ON p.voucher = f.voucher


where f.id_transfer = '$id_transfer' and cod_bloco_faturamento = '$bloco' ";     
$resultado = mysql_query($sql) or die( mysql_error());
while ($linha = mysql_fetch_assoc($resultado)) {

$bloco = $linha["cod_bloco_faturamento"];
$id_empresa = $linha["id_empresa"];
$valor1 = $linha["valor"];
$valor = 'R$' . number_format($valor1, 1, ',', '.');
$vencimento = $linha["data_vencimento"];
    
asked by anonymous 19.10.2015 / 03:28

1 answer

0

In the where clause you can add the IN operator.

where f.id_transfer = '$id_transfer' and cod_bloco_faturamento = '$bloco' 
AND id_linha IN ('$range');"

However, I want to add an alert, since executing the code the way you are using opens the select to an SQL Injection attack.

Edit: I would advise composing the selects using PDO or MYSQLi

    
06.06.2016 / 13:55