1

I'm trying to pull some data from MySQL using an Array that was fetch from a first query. Everything's fine all the way to the implode after that, it's been a headache for me. Can someone help me?

<?php

include("conect.php");

$colcod = $_POST['rubi'];

// $colcod = 'rubi';

include("config/conectar.php");
$colonias="SELECT zip FROM the_codes WHERE  coloni LIKE '%$colcod%' ORDER BY coloni";
$resultados = $asies->query($colonias);
    while ($fila = $resultados->fetch_array()){
      $codigo[]=$fila['zip'];
    }

array_pop($codigo);
$codigo = implode(', ',$codigo);
//print_r ($codigo); // <- Imprimimos para asegurarnos que todo está bien

$usuarios = "SELECT * FROM reg_temp WHERE zip IN ('".$codigo."') ";
$respuesta = $asies->query($usuarios);
while ($fila = $respuesta -> fetch_array()){
    $nombre = $fila['name'];
echo $nombre;
}
?>
4

1 に答える 1

0

$mycode = implode(', ',$mycode);join配列はすでにコンマ区切りの文字列に変換されているため、内部で使用する必要はありませんIN(...)

$usr = "SELECT * FROM reg_temp WHERE zip IN('".$mycode)."')";
$results = $asies->query($usr);
while ($row = $results->fetch_array())
{
    $name = $row['name'];
    echo $name;
}

また、注意while ($row = $results-> fetch_arra())してください、それは正しくありません。

于 2012-07-08T21:37:59.930 に答える