1

我正在尝试使用从第一个查询中获取的数组从 MySQL 中提取一些数据。在那之后一切都很好,一直到内爆,这让我很头疼。有人能帮我吗?

<?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 回答