Pass fix value to query


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:


$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)):


This is my arrangement

array(1) {
  array(10) {
    string(1) "1"
    string(1) "1"
asked by Cesar Gutierrez Davalos 22.07.2017 в 19:24

1 answer


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.


answered by 22.07.2017 / 19:30