Pass fix value to query

1

I am trying to pass a value of my fix to my query but at the moment of doing it it says to me:

  

Array to string conversion

My fix comes from a function in a file called functions.php

It is the first value of my array that I want to pass to the query of my functions.php file

I have a variable that collects the result of my main function:

$emit = obtener_mensajes($conexion, $us);

This is where I want to insert my query and the variable:

<?php 

$query = "SELECT * FROM messages WHERE idEmitter IN ($us, $emit[0]) AND idReceiver IN ($emit[0], $us) ORDER BY sent ASC" ;

$run = $conexion->query($query);

while ($row = $run->fetch(PDO::FETCH_ASSOC)):
    //var_dump($row);

?>

This is my arrangement

array(1) {
  [0]=>
  array(10) {
    ["idEmitter"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
    
asked by Cesar Gutierrez Davalos 22.07.2017 в 19:24
source

1 answer

2

The problem that is telling you is that you are trying to insert an array directly into the query.

This is because although you access the first position of the array $emit , this in turn has an array contained in that position, so you would have to access the associative keys of this second array to access each of their values and be able to include them in your query.

Example:

$emit[0]["idEmitter"];
$emit[0][0];
    
answered by 22.07.2017 / 19:30
source