Browse Array with PHP to insert values in SQL query

0

I have the following code:

if(isset($_POST['aplicar'])) {
                                $bafle = $_POST['bafle'];
                                $marca1 = $_POST['marca1'];
                                    if (is_array($marca1))
                                    {
                                      for ($i=0;$i<count($marca1);$i++)
                                      {
                                      }
                                    }
                                $size = $_POST['size'];
                                $j = 0;
                                foreach($size as $elemento)
                                {
                                   echo "$elemento<br>";
                                   ++$j;
                                }
                                $sistema = $_POST['sistema'];
                                $sql="SELECT * FROM 'jsonBuscador' WHERE 'tags' LIKE '%$marca1[0]$elemento$sistema%' OR 'tags' LIKE '%$marca1[1]$elemento$sistema%'";

In which what I'm trying to do is get the data sent from a form in the form of an array, then go through that array and insert the values found inside the array in a SQL query, unfortunately I can not perform this action and would like you could help me, thanks.

    
asked by user3033258 17.08.2018 в 00:23
source

1 answer

0

I leave you an example of concatenating the values:

$values = [];

foreach([array] as [value]){
    $values .= " AND [column] = [value]";
}

$sth = $this->Connection->prepare("SELECT {$Select} FROM {$TableName} WHERE {$values}");
$sth->execute();
return $data = $sth->fetch(\PDO::FETCH_ASSOC);
    
answered by 17.08.2018 в 16:13