elimde şöyle küçük bir script var yorum yazıyoruz fakat 100 yorum olsada 1000 yorum olsada hepsini ilk sayfada gösteriyor ben sadece ilk yada son 10 tanesini göstermesini istiyorum , diğerleri 2. 3. sayfada olucak bunu nasıl sağlıyabiliriz kod bu
Alıntı
// ##### GET COMMENTS #####
$comments_query = mysql_query ("SELECT * FROM comments LEFT JOIN users ON comments.user_id = users.user_id WHERE comments.file_id = '" . intval($_GET['id']) . "' ORDER BY comments.added");
while ($comment = mysql_fetch_array ($comments_query))
{
$comment['comment'] = stripslashes ($comment['comment']);
$comment['title'] = stripslashes ($comment['title']);
$comment['added'] = date('F d, Y', $comment['added']);
$comments .= $tpl->pull_template ('comment');
}
edit : şöyle bir kod oluşturdum fakat buda çalışmadı , ?sayfa=2 , ?sayfa=3 'e geçincede aynı ilk 10 yorum görünüyor.
sizce nerde hata?
// ##### GET COMMENTS #####
$perpage = 10;
if( intval($_GET['sayfa']) )
$page = $_GET['sayfa'];
else
$page = 1;
$comments_query = mysql_query ("SELECT * FROM comments
LEFT JOIN users ON comments.user_id = users.user_id
WHERE comments.file_id = '" . intval($_GET['id']) . "'
ORDER BY comments.added LIMIT ".$perpage*($page-1).", $perpage");
while ($comment = mysql_fetch_array ($comments_query))
{
$comment['comment'] = stripslashes ($comment['comment']);
$comment['title'] = stripslashes ($comment['title']);
$comment['added'] = date('F d, Y', $comment['added']);
$comments .= $tpl->pull_template ('comment');
}
// toplam kayit sayisini bul -> $t_rec
$sql = "SELECT COUNT(*) FROM comments
LEFT JOIN users ON comments.user_id = users.user_id
WHERE comments.file_id = '" . intval($_GET['id']) . "'";
list($t_rec) = mysql_fetch_row( mysql_query($sql) );
// bu kontrolü ozellestirebilirsin
for($i=1; $i<=ceil($t_rec/$perpage); $i++) {
echo "<a href='?sayfa=$i'>$i</a> | ";
}