Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!