Misafir adlı üyeden alıntı: mesajı görüntüle
Yine aynı kod ile bunu yapabilirsiniz, fakat bir koşul daha koymanız lazım.

$session1 = $_SESSION['ogrenciad'];
$session2 = $_SESSION['ogrencisinif'];
$sorgu = $db->prepare("select * from odev where odevogrenci=? and ogrencisinif=?");
$sorgu->execute(array($session1,$session2));
while($sorguoku = $sorgu->fetch(PDO::FETCH_ASSOC)){

echo $sorguoku["ogrenci_odevi"];

}
tamam deniyeyim