0

I have two queries. The first one is generating a list of ids (col_id_8) I want to use in the second query. I'm not sure what I am doing wrong. Thank you!

$sql = 'SELECT DISTINCT col_id_8 FROM exp_channel_grid_field_84 WHERE entry_id = :entry_id';
    $stmt = $conn->prepare($sql);

    try {
        $stmt->execute(array('entry_id' => $entry_id));
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as $row) {
            $fullcodes[] = $row['col_id_8'];
        }
    } catch(PDOException $e) { error_log($e->getMessage(),0); }

    $sql = 'SELECT DISTINCT name FROM stix_live_orders WHERE code in (:allcodes) ORDER BY name ASC LIMIT 4';
    $stmt = $conn->prepare($sql);

    try {
        $stmt->execute(array('allcodes' => $fullcodes));
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        # MORE CODE
    }
1
  • you can do this in a single query using a subselect Commented Nov 9, 2014 at 16:57

1 Answer 1

2

Try $stmt->execute(array('allcodes' => implode( ',', $fullcodes ) )); instead $stmt->execute(array('allcodes' => $fullcodes));

Sign up to request clarification or add additional context in comments.

1 Comment

For some reason it didn't work there, but when I put it in the prepared statement it worked like a charm! Since this is a contained area, I'll just leave it :) Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.