简体   繁体   中英

Convert Array for mySQL Query

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
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM