1

行を選択して配列で返す pdo ステートメントがあります。ページネーションを使用して、1 ページあたり 12 件の結果を表示しています。を直接入力するLIMIT 12, 12と、代わりにLIMIT ?, ?ステートメントが正しく機能します。

両方の変数の bindParam で何が間違っていますか?

どちらの変数にも正しいデータが含まれています。

私が使用している関数は次のとおりです。

// Retrieve active posts
function retrieve_active_posts(){
    //test the connection
    try{
        //connect to the database
        $dbh = new PDO("mysql:host=db2940.oneandone.co.uk;dbname=db348699391","xxx", "xxx");
    //if there is an error catch it here
    } catch( PDOException $e ) {
        //display the error
        echo $e->getMessage();

    }

    // Get all the posts
    $stmt = $dbh->prepare(" SELECT  p.post_id, post_year, post_desc, post_title, post_date, img_file_name, p.cat_id
                            FROM    mjbox_posts p
                            JOIN    mjbox_images i
                            ON      i.post_id = p.post_id
                                    AND i.cat_id = p.cat_id
                                    AND i.img_is_thumb = 1
                                    AND post_active = 1
                            ORDER BY post_date
                            DESC
                            LIMIT ?,?");
    $stmt->bindParam(1, $limit);
    $stmt->bindParam(2, $offset);                       
    $stmt->execute();


    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

            $resultarray[] = $row;
    }

    return $resultarray;
}

どうもありがとう

4

2 に答える 2