Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
Filling an array to use as a parameter for WHERE clause

I'm trying to fetch all of the position_id's in order to fill an array which I can then pass to the second statement to fetch all of the rows containing a position_id in the array. I'm trying to use this data to fill a dropdown menu.

Am I doing this properly or is there a better way to do this?

// $_POST['aid'] == election_id
if(isset($_POST['aid'])) {
    // Get's the rows with corresponding election_id 
    $stm = $db->prepare("SELECT * FROM position_elections WHERE election_id = " . $_POST['aid']);
    $stm->execute();
    $position_ids = [];
    if ($row = $stm->fetchAll(PDO::FETCH_ASSOC)) 
    {
        $position_id = $row['position_id'];
        array_push($position_ids, $position_id);
    }

    $ids = join("','",$position_ids);
    $stm2 = $db->prepare("SELECT * FROM positions WHERE position_id IN ($ids)");
    $stm2->execute();
    $positions = $stm2->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($positions);

}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda